ImportError: cannot import name 'ControlType' from 'libcamera'(unknown location)

I got a new Arducam IMX519 Autofocus camera and I have been fighting for weeks to try and get it to work within Python. Out of the box within minutes I was able to get it working with libcamera so I know the camera itself works, but I’ve followed literally 50 tutorials and I can’t find any way to make it work in Python. The latest attempt has been to go back to the Arducam site and follow the instructions provided here: Picamera2 with Arducam V1/V2/HQ/16MP-AF/64MP-AF/Pivariety Cameras (Guide) - Arducam

Everything is installed with no errors. Then when I try to run any of the samples provided in the Github repo: GitHub - raspberrypi/picamera2: New libcamera based python library I always get the same error:

ImportError: cannot import name ‘ControlType’ from ‘libcamera’ (unknown location)

Or more sepcifically

trezero@raspberrypi:~/Applications/picamera2/examples $ python3 easy_capture.py
Traceback (most recent call last):
  File "/home/trezero/Applications/picamera2/examples/easy_capture.py", line 3, in <module>
    from picamera2 import Picamera2
  File "/home/trezero/.local/lib/python3.9/site-packages/picamera2/__init__.py", line 1, in <module>
    from .configuration import CameraConfiguration, StreamConfiguration
  File "/home/trezero/.local/lib/python3.9/site-packages/picamera2/configuration.py", line 1, in <module>
    from .controls import Controls
  File "/home/trezero/.local/lib/python3.9/site-packages/picamera2/controls.py", line 4, in <module>
    from libcamera import ControlType, Size, Rectangle
ImportError: cannot import name 'ControlType' from 'libcamera' (unknown location)

This is running an extremely simple app which is this:

#!/usr/bin/python3

from picamera2 import Picamera2

picam2 = Picamera2()

# Capture one image with the default configurations.
picam2.start_and_capture_file("test.jpg")

# Capture 3 images. Use a 0.5 second delay after the first image.
picam2.start_and_capture_files("test{:d}.jpg", num_files=3, delay=0.5)

Can someone please help me understand how to get past this error?

@trezero

Try uninstall libcamera

python3 -m pip uninstall libcamera

and then try the Picamera2 again.

Unfortunately I just re-imaged to a 64 bit Raspberry Pi image based on reading some other sites. Can you confirm if this should work on the 64Bit Raspberry Pi OS?

@trezero

Re-burning the system can also solve the same problem.

The reason is that you installed our previous libcamera python library, the idea to solve it is to delete the dependency.

Following the instructions provided here exactly ended up being the thing that finally worked

@trezero

This is really the key to solving this problem.

Did the same thinking as I did.

@Edward One last thing though. After following this, the one thing that no longer works that always worked before is autofocus. When I try this now I get this error:

libcamera-still -t 0 --viewfinder-width 2328 --viewfinder-height 1748 --autofocus
Closing Libcamera application(frames displayed 0, dropped 0)
Camera stopped!
Tearing down requests, buffers and configuration
Camera closed
ERROR: *** unrecognised option ‘–autofocus’ ***

Any ideas? Is there something missing that I need to install for Autofocus to work? Also, how do I use Autofocus within Python? I couldn’t find anything about it with Picamera2.

I really appreciate all your help!

@Edward any ideas here? I’m still really stuck. No matter what I do it seems impossible to get autofocus to work within Python while running Picamera2

@trezero

Take a look at the information about libcamera

sudo dpkg -l | grep libcamera