raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
901 stars 190 forks source link

[BUG] ImportError: cannot import name 'V4L2_CID_MPEG_VIDEO_H264_MAX_QP' from 'v4l2' #615

Closed fnorlund closed 1 year ago

fnorlund commented 1 year ago

Describe the bug Cannot import picamera2 after upgrade of RPi OS

To Reproduce If you have the same issue $python3

import picamera2

Expected behavior No error when importing picamera2

Console Output, Screenshots When importing picamera2 after OS upgrade with $python3

import picamera2 Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3/dist-packages/picamera2/init.py", line 7, in from .picamera2 import Picamera2, Preview File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 23, in from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality File "/usr/lib/python3/dist-packages/picamera2/encoders/init.py", line 2, in from .h264_encoder import H264Encoder File "/usr/lib/python3/dist-packages/picamera2/encoders/h264_encoder.py", line 5, in from v4l2 import (V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, ImportError: cannot import name 'V4L2_CID_MPEG_VIDEO_H264_MAX_QP' from 'v4l2' (/home/fredrik/.local/lib/python3.9/site-packages/v4l2.py)

Hardware : Please state what kind of Pi you are using, and what camera is attached. Rpi 3B+ Raspberry Pi Camera v2.1

Additional context The error came after I recently updated the os $sudo apt update $sudo apt upgrade The upgrade was successful with no errors $sudo reboot

$cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

$uname -m aarch64

$pip3 show picamera2 Name: picamera2 Version: 0.3.9 Summary: The libcamera-based Python interface to Raspberry Pi cameras, based on the original Picamera library Home-page: https://github.com/RaspberryPi/picamera2 Author: Raspberry Pi & Raspberry Pi Foundation Author-email: picamera2@raspberrypi.com License: BSD 2-Clause License Location: /usr/lib/python3/dist-packages Requires: Required-by:

Thanks for your support!

jenyak commented 1 year ago

I had same error, as in #600 update python3-v4l2 to version 0.3.2 helped. I also had v4l2-python3 0.3.1 installed via pip, removed it to use the system library

fnorlund commented 1 year ago

Thanks jenyak for your fast response.

I solved the problem by removing the old v4l2.py from the local python installation so the system-wide installation path was used instead.