[BUG] Raspberry Pi 4: Cannot import name 'Size' or 'ControlType' from libcamera depending on version of libcamera
See original GitHub issueDescribe the bug I can’t seem to import from picamera2 regardless of the libcamera version I’m using.
When I enable “Legacy Camera Support” in raspi-config, picamera2 fails to import ‘Size’ from libcamera. When I install a more recent libcamera, picamera2 fails to import ‘ControlType’.
I also checked the libcamera API documentation (https://www.libcamera.org/api-html/classes.html) and I don’t see a ControlType class?
Is there a recommended version of libcamera to install?
To Reproduce Raspberry Pi 4 (4 GB RAM model) Raspberry PI OS Lite (32 bit, Buster-base Release 2022-04-04)
Sample program:
from picamera2 import PiCamera
# That's all that's required
Install picamera2 with no gui according to workaround here: https://github.com/raspberrypi/picamera2/issues/184
In sudo raspi-config
Interface Options -> Legacy Camera, enable Legacy Camera suport. Reboot
Run sample program. Note “cannot import name ‘Size’” error
Install libcamera from wheel: https://github.com/ArduCAM/RaspberryPi/blob/master/Motorized_Focus_Camera/python/libcamera-1.0.2-cp39-cp39-linux_armv7l.whl
python3 -m pip install ./libcamera-1.0.2-cp39-cp39-linux_armv7l.whl
Run sample program. Note “cannot import name ‘ControlType’”
Expected behaviour importing PiCamera works
Console Output, Screenshots
With “legacy camera”
Traceback (most recent call last):
File "/home/pi/RaspberryPi/Motorized_Focus_Camera/python/picam2.py", line 1, in <module>
from picamera2 import PiCamera
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/__init__.py", line 1, in <module>
from .configuration import CameraConfiguration, StreamConfiguration
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/configuration.py", line 1, in <module>
from .controls import Controls
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/controls.py", line 4, in <module>
from libcamera import ControlType, Size, Rectangle
ImportError: cannot import name 'Size' from 'libcamera' (/usr/lib/python3/dist-packages/libcamera/__init__.py)
With more recent libcamera:
Traceback (most recent call last):
File "/home/pi/RaspberryPi/Motorized_Focus_Camera/python/./Autofocus.py", line 5, in <module>
from RpiCamera import Camera
File "/home/pi/RaspberryPi/Motorized_Focus_Camera/python/RpiCamera.py", line 10, in <module>
from picamera2 import Picamera2, Preview
File "/home/pi/.virtualenvs/moto_cam/lib/python3.9/site-packages/picamera2/__init__.py", line 1, in <module>
from .configuration import CameraConfiguration, StreamConfiguration
File "/home/pi/.virtualenvs/moto_cam/lib/python3.9/site-packages/picamera2/configuration.py", line 1, in <module>
from .controls import Controls
File "/home/pi/.virtualenvs/moto_cam/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' (/home/pi/.virtualenvs/moto_cam/lib/python3.9/site-packages/libcamera.cpython-39-arm-linux-gnu
**Hardware :**
Raspberry Pi 4
Arducam 5MP (Repros with RaspiCam v1.3 as well)
**Additional context**
With Legacy Camera support enabled,
$ sudo ldconfig -v | grep camera libcamera-base.so.0 -> libcamera-base.so.0.0.0
libcamera.so.0 -> libcamera.so.0.0.0
With it disabled, but installing a wheel:
$ sudo ldconfig -v | grep camera $
Issue Analytics
- State:
- Created a year ago
- Comments:14 (2 by maintainers)
Top GitHub Comments
This is my list of commands JUST after installing a clean Raspberry Pi4 Bulleyes 64-bit (64-bit is a MUST to have all to work):
Use dmesg to know if all working fine:
At this point libcamera-apps are already installed and working:
Follow activity to enable camera focus motor management (if camera support it because motorized):
Packages to install to have Picamera2, OpenCV working:
@shineworld I have been fighting to get my camera working for the past 3 weeks and your instructions are the first and only ones that actually worked. Thank you SOO Much! I wish I could buy you a beer (or 5!). Truly appreciate you.