[BUG] ImportError: cannot import name 'V4L2_CID_MPEG_VIDEO_H264_PROFILE' from 'v4l2'

Open
#1,022 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
embedded-iot

Research direction

Start with picamera2/encoders/h264_encoder.py and compare its imported H.264 constants with the installed v4l2.py reported in the traceback. Reproduce the Python 3 import failure, then verify that importing Picamera2 completes without the ImportError.

Written by the indexing model from the issue text.

Description

Please only report one bug per issue!

Describe the bug
Cannot use picamera2 with OpenCV

To Reproduce
If you have the same issue
$python3

Expected behaviour
No error when importing picamera2

Console Output, Screenshots
Traceback (most recent call last):
File "/home/dima/Desktop/test.py", line 2, in
from picamera2 import Picamera2
File "/usr/lib/python3/dist-packages/picamera2/init.py", line 9, in
from .picamera2 import Picamera2, Preview
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 26, in
from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality
File "/usr/lib/python3/dist-packages/picamera2/encoders/init.py", line 21, in
from .h264_encoder import H264Encoder
File "/usr/lib/python3/dist-packages/picamera2/encoders/h264_encoder.py", line 3, in
from v4l2 import (V4L2_CID_MPEG_VIDEO_H264_I_PERIOD,
ImportError: cannot import name 'V4L2_CID_MPEG_VIDEO_H264_PROFILE' from 'v4l2' (/home/dima/cv/lib/python3.11/site-packages/v4l2.py)

Hardware :
Please state what kind of Pi you are using, and what camera is attached.

Additional context
Add any other context about the problem here.
Raspberry Pi 4 Model B Rev 1.5
Raspberry Pi Camera rev 1.3

Name: v4l2-python3
Version: 0.3.2
Summary: Python bindings for the v4l2 userspace api.
Home-page: https://pypi.org/project/v4l2-python3/
Author:
Author-email:
License: GPLv2
Location: /home/dima/cv/lib/python3.11/site-packages

Name: picamera2
Version: 0.3.18
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

Dominant language
Python
Stars
1.2k
Forks
258
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/picamera2

All issues in raspberrypi/picamera2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.