ImportError: cannot import ControlType from libcamera on Raspberry Pi 4 32-bit Motorized Focus Camera

Hi, I’m trying to get the Motorized Focus Camera (B0393) working on my Raspberry Pi 4 and I keep hitting the same error. I’m following the paper instruction manual and the online docs, but the motor control examples just won’t run. The camera itself works fine with libcamera, but anything that pulls in picamera2 blows up.

Running python FocuserExample.py -i 10 from /home/etscalsi/RaspberryPi/Motorized_Focus_Camera/python/ gives me this:

Traceback (most recent call last):
  File "/home/etscalsi/RaspberryPi/Motorized_Focus_Camera/python/FocuserExample.py", line 27, in <module>
    from RpiCamera import Camera
  File "/home/etscalsi/RaspberryPi/Motorized_Focus_Camera/python/RpiCamera.py", line 10, in <module>
    from picamera2 import Picamera2, Preview
  File "/usr/local/lib/python3.9/dist-packages/picamera2/__init__.py", line 1, in <module>
    from .configuration import CameraConfiguration, StreamConfiguration
  File "/usr/local/lib/python3.9/dist-packages/picamera2/configuration.py", line 1, in <module>
    from .controls import Controls
  File "/usr/local/lib/python3.9/dist-packages/picamera2/controls.py", line 4, in <module>
    from libcamera import ControlType, Size, Rectangle
ImportError: cannot import name 'ControlType' from 'libcamera' (/home/etscalsi/.local/lib/python3.9/site-packages/libcamera.cpython-39-arm-linux-gnueabihf.so)

Setup: Raspberry Pi 4, latest Raspberry Pi OS (32-bit version). picamera2 is at /usr/local/lib/python3.9/dist-packages/picamera2, and libcamera is showing up at /home/etscalsi/.local/lib/python3.9/site-packages/libcamera.cpython-39-arm-linux-gnueabihf.so which seems a bit odd to me?

I’ve reinstalled the OS and followed the instructions several times already and still get the same error. Also, does the OS version matter — I installed the 32-bit version, should it have been 64-bit? I’m trying to get this module working to assess achievable image quality for a new IOT product. Bug report files attached.

Hi, thanks for the very detailed report. First thing: don’t worry about the architecture — we support both 32-bit and 64-bit, so the fact you installed the 32-bit OS is not the cause here.

Let’s get a proper diagnostic. Please reboot the board first, then run:

wget -O arducam-camera-bug-report https://github.com/ketai-dhr/arducam-camera-bug-report/releases/download/tools/arducam-camera-bug-report
chmod +x ./arducam-camera-bug-report
./arducam-camera-bug-report

That produces an arducam-bug-report.txt in the current directory. Attach that file and we’ll dig in. Also, can you tell me what picamera2 version you have installed? sudo pip3 list | grep picamera2 will show it.

OK, rebooted and ran the bug report script — file attached. Here’s the picamera2 version:

$ sudo pip3 list | grep picamera2
picamera2 0.3.3

For reference, the commands I’ve been following (from the earlier instructions) are:

wget -O arducam-camera-bug-report https://github.com/ketai-dhr/arducam-camera-bug-report/releases/download/tools/arducam-camera-bug-report
chmod +x ./arducam-camera-bug-report
./arducam-camera-bug-report
sudo apt remove libcamera
sudo apt remove libcamera-dev
wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh
./install_pivariety_pkgs.sh -p libcamera_dev
./install_pivariety_pkgs.sh -p libcamera_apps

Not sure if any of that is where things went wrong.

Thanks, that version is the key. You’re on picamera2 0.3.3, and that’s the wrong version for this setup — it’s what’s breaking the ControlType import.

Pin it down to 0.3.2 with:

sudo pip3 install picamera2==0.3.2

Then try the focuser example again and let us know how it goes.

I ran that command and rebooted the board, but I still get the identical error:

ImportError: cannot import name 'ControlType' from 'libcamera' (/home/etscalsi/.local/lib/python3.9/site-packages/libcamera.cpython-39-arm-linux-gnueabihf.so)

And just to confirm, pip still reports picamera2 0.3.3 after the install:

$ sudo pip3 list | grep picamera2
picamera2 0.3.3

Not sure it’s actually downgrading.

That output tells me something is messing with libcamera on your device. Quick question — did you ever compile libcamera manually, or install our previous libcamera-python library at some point? A leftover build like that would shadow the correct one, and it would also explain why the pip downgrade isn’t sticking — your local .so in ~/.local is being picked up instead.

Try removing the libcamera-python library again:

sudo pip3 uninstall libcamera

Then reinstall picamera2==0.3.2 and retest.

Tried that too, still the same error. Honestly, I started with a clean build of my RPi 4 — the only thing I’ve done on it is try to install the software required for this camera, so I’m not sure where a manual libcamera would even have come from.

Could you send me the instructions to install the camera again from scratch? I’ll replace the OS so it’s completely new and try yet again. Current state:

sudo pip3 uninstall libcamera
sudo pip3 install picamera2==0.3.2
$ sudo pip3 list | grep picamera2
picamera2 0.3.3

Still showing 0.3.3 no matter what.

No problem — here’s the clean sequence to follow on a fresh OS image. Do it in this order and reboot where indicated.

  1. Flash a fresh Raspberry Pi OS image (32-bit is fine).
  2. Update the system: sudo apt update && sudo apt full-upgrade
  3. Install our libcamera stack:
wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh
./install_pivariety_pkgs.sh -p libcamera_dev
./install_pivariety_pkgs.sh -p libcamera_apps
  1. Reboot.
  2. Install picamera2 pinned: sudo pip3 install picamera2==0.3.2
  3. Reboot once more, then run FocuserExample.py.

Important part is to not mix a pip-installed libcamera with the apt/pivariety one — keep only the apt stack for libcamera and pin picamera2. Give that a go and let us know how you get on.

Good news — I rebuilt the RPi OS again today and followed a couple of different installation instructions, and it now appears to be working. The ImportError is gone and the focuser example runs. Thank you for your help — I may have additional questions soon once I start testing image quality.

Great to hear it’s up and running. To recap where this landed: the ControlType ImportError came down to the picamera2/libcamera mix on the device — a stale libcamera in ~/.local was conflicting with the APT/pivariety libcamera, and picamera2 wouldn’t drop below 0.3.3 with that conflict present (which is why the pip downgrade kept reporting 0.3.3). A clean OS image, the pivariety libcamera packages, and a pinned picamera2 0.3.2 sorted it out.

If you ever see the same import error again after an update, first check sudo pip3 list | grep picamera2 and make sure no stray libcamera is installed under ~/.local. Post back whenever you start your image-quality testing.