Installation of YOLO creates problems with DroneKit-Python Flight Scripts on Raspberry Pi

At Kashmir World Foundation we use YOLO and DroneKit-Python for many of our airborne missions to protect endangered species. Unfortunately the current pip3 install ultralytics causes our Flight Scripts to fail. We would much appreciate assistance in understanding the problem and deriving a solution:

YOLO Installation created the following error

(DroneKit) pi@raspberrypi:~/Imagery_Challenge $ python3 20250725_Imagery_Challenge.py --connect 127.0.0.1:14550

Traceback (most recent call last):

  File “/home/pi/Imagery_Challenge/20250725_Imagery_Challenge.py”, line 17, in

  from picamera2 import Picamera2 # Libcamera-based replacement for Picamera which was a Python interface to the Raspberry Pi’s legacy camera stack

  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File “/usr/lib/python3/dist-packages/picamera2/__init__.py”, line 11, in

  from .picamera2 import Picamera2, Preview

  File “/usr/lib/python3/dist-packages/picamera2/picamera2.py”, line 30, in

  from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality

  File “/usr/lib/python3/dist-packages/picamera2/encoders/__init__.py”, line 7, in

  from .encoder import Encoder, Quality

  File “/usr/lib/python3/dist-packages/picamera2/encoders/encoder.py”, line 12, in

  from ..request import _MappedBuffer

  File “/usr/lib/python3/dist-packages/picamera2/request.py”, line 13, in

  import simplejpeg

  File “/usr/lib/python3/dist-packages/simplejpeg/__init__.py”, line 1, in

  from ._jpeg import encode_jpeg, encode_jpeg_yuv_planes

  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

The first step would be to configure a clean virtual environment and attempt installation of both ultralytics and DroneKit-Python at the same time. The package manager, I recommend using uv, should determine if there are dependency conflicts at install time. Sharing the full details of your operating environment, python version, list of all packages, operating system, and hardware specifics, will also greatly help for others either encountering a similar issue or being able to help provide support.

If this doesn’t resolve the issue, you’ll need to determine where or how the two libraries have a conflict. Once you do, you’ll will need to open a pull request in one or both of the repositories to address the issue.

My guess from the error is that it’s either Numpy or CPython related. It would be best to try installing using a fresh virtual environment as mentioned above.

Hi Burhan .. I installed DroneKit-Python in a virtual python environment on a fresh and updated version of 64-bit Bookworm .. I ran several of our test flight scripts including the imagery challenge script to verify hardware and software were functioning. I then installed YOLO using pip install ultralytics. Then the flight scripts failed. One of our interns attempted to identify and resolve the issue last night and reported, “I did pip install -U simplejpeg after installing ultralytics and now it passes the import step without error in the challenge script, it uninstalls version 1.8.1 and installs 1.8.2. If this solves the problem for you I can include it in new instructions for the next challenge script.” I have yet to test this myself.

Hi Burhan .. I tried pip3 install -U simplejpeg and replicated the success of our intern. Now I am trying to understand what took place:

  1. Did pip3 install ultralytics install an older version of simplejpeg?

  2. Did pip3 install ultralytics not install any version of simplejpeg, but install a new version of numpy that required a new version of simplejpeg?

  3. Would sudo apt update followed by apt full-upgrade have resolved the problem?

  4. Should pip3 install simplejpeg be included in pip3 install ultralytics?

Ultralytics doesn’t install simplejpeg. The issue could be due to numpy installation getting changed.

1 Like

Hi Toxite .. Indeed the issue was caused by a newer version of numpy installed by pip3 install ultralytics that we fixed by pip3 install -U simplejpeg. Could we have also fixed the issue by apt full-upgrade? Because we use DroneKit-Python and YOLO on many mission systems, we are looking for a more consistent approach.

I found this thread which describes the same issue as yours:

Also this issue:

So the solution seems to be to upgrade simplejpeg. You can do that alongside Ultralytics installation by running pip install -U ultralytics simplejpeg.