I want to use picamera2 and opencv in a program on my Raspberry Pi 5. This is what I am doing.
- I did a fresh install of Bookworm
- sudo apt update
-- - Check that I can use picamera2 in python by going into repl and typing import picamera2. Works fine.
- Install opencv
- - I get warnings that numpy version was 1.24.2 and it will be updated to 2.2.6When I go into the repl, I can import cv2, but no longer picamera2This appears to be a conflict over the version of numpy in my venv, but I don't know how to fix this. Any ideas?
- I did a fresh install of Bookworm
- sudo apt update
-
Code:
python3 -m venv --system-site-packages myprojectnameCode:
source myprojectname/bin/activate- Install opencv
-
Code:
pip install opencv-pythonCode:
(myprojectname) myname@mytarget:~/myprojectname $ pip install opencv-pythonLooking in indexes: https://pypi.org/simple, https://www.piwheels.org/simpleCollecting opencv-python Downloading opencv_python-4.12.0.88-cp37-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (45.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 45.9/45.9 MB 7.2 MB/s eta 0:00:00Collecting numpy<2.3.0,>=2 Downloading numpy-2.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (14.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.3/14.3 MB 11.2 MB/s eta 0:00:00Installing collected packages: numpy, opencv-python Attempting uninstall: numpy Found existing installation: numpy 1.24.2 Not uninstalling numpy at /usr/lib/python3/dist-packages, outside environment /home/myname/myprojectname Can't uninstall 'numpy'. No files were found to uninstall.Successfully installed numpy-2.2.6 opencv-python-4.12.0.88Code:
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import cv2>>> import picamera2Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3/dist-packages/picamera2/__init__.py", line 11, in <module> from .picamera2 import Picamera2, Preview File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 30, in <module> from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality File "/usr/lib/python3/dist-packages/picamera2/encoders/__init__.py", line 5, in <module> from .encoder import Encoder, Quality File "/usr/lib/python3/dist-packages/picamera2/encoders/encoder.py", line 12, in <module> from ..request import _MappedBuffer File "/usr/lib/python3/dist-packages/picamera2/request.py", line 13, in <module> import simplejpeg File "/usr/lib/python3/dist-packages/simplejpeg/__init__.py", line 1, in <module> from ._jpeg import encode_jpeg, encode_jpeg_yuv_planes File "simplejpeg/_jpeg.pyx", line 1, in init simplejpeg._jpegValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject>>> Statistics: Posted by ebrewste — Sun Jul 27, 2025 2:42 am