Toxite
July 30, 2025, 7:52am
7
I found this thread which describes the same issue as yours:
Also this issue:
opened 06:18PM - 08 Aug 24 UTC
closed 06:40PM - 08 Aug 24 UTC
**Describe the bug**
python-picamera2 does not import when using numpy 2.x
*… *To Reproduce**
Ensure latest picamera2 python system package is installed as well as numpy 1.26.4 or older (1.24.2 seems to be the system package version)
```sh
$ apt list python3-picamera2
python3-picamera2/stable,stable,now 0.3.19-1 all [installed]
$ python3 -m venv --system-site-packages .venv
$ source .venv/bin/activate
$ pip freeze |grep -E 'numpy|picamera|scipy'
numpy==1.24.2
picamera2==0.3.19
scipy==1.10.1
```
Validate import works with numpy 1.x
```sh
$ python3 -c 'from picamera2 import Picamera2' && echo $?
0
```
Upgrade numpy to latest 2.x (and scipy, requires newer)
```sh
$ pip install numpy==2.0.1 scipy==1.14.0
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting numpy==2.0.1
Using cached numpy-2.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (13.9 MB)
Collecting scipy==1.14.0
Using cached scipy-1.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (35.6 MB)
Successfully installed numpy-2.0.1 scipy-1.14.0
```
Import picamera2 and see that it fails
```sh
$ python3 -c 'from picamera2 import Picamera2' && echo $?
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/picamera2/__init__.py", line 9, in <module>
from .picamera2 import Picamera2, Preview
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 27, in <module>
from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality
File "/usr/lib/python3/dist-packages/picamera2/encoders/__init__.py", line 6, in <module>
from .jpeg_encoder import JpegEncoder
File "/usr/lib/python3/dist-packages/picamera2/encoders/jpeg_encoder.py", line 3, in <module>
import simplejpeg
File "/usr/lib/python3/dist-packages/simplejpeg/__init__.py", line 1, in <module>
from ._jpeg import encode_jpeg
File "simplejpeg/_jpeg.pyx", line 1, in init simplejpeg._jpeg
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```
**Expected behavior**
Import should not fail with latest numpy
**Console Output, Screenshots**
See repro steps above
**Hardware :**
```
Model : Raspberry Pi 5 Model B Rev 1.0
Revision : d04170
Pi OS 64-bit
Linux rp-2ccf670e7060 6.6.31+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux
```
So the solution seems to be to upgrade simplejpeg. You can do that alongside Ultralytics installation by running pip install -U ultralytics simplejpeg.