Using ultralytics with ROS2 Humble

I’m attempting to create a ROS2 (Humble) node (Python) that receives image data from a ROS2 publisher (Isaac Sim) and performs predictions on the images using the predict() method on a YOLO model.

The problem I’ve run into is that ROS2 (specifically its cv_bridge utility) requires an old version of numpy (< 2.0) while the current ultralytics library requires something > 2.

I’ve actually managed to get this node to work by deleting the newer numpy version pulled in during the ultralytics install (the system then finds an older version of numpy that’s installed) but I’m hoping there’s a cleaner solution.

Thank you.

Ultralytics doesn’t require numpy>2, but if you don’t specify any version, then pip willl install the latest.

You can specify numpy version during installation.

pip install ultralytics "numpy<2"
1 Like

Thank you!

1 Like

Glad it’s sorted! For a clean, reproducible setup with ROS2 Humble, pin NumPy<2 (1.26.x is a safe choice) and consider opencv-python-headless for headless ROS nodes. Example:

requirements.txt

ultralytics
numpy<2
opencv-python-headless

Install with:

pip install -r requirements.txt

If you need tighter control over dependencies, check the custom installation methods in our Install Ultralytics guide, which shows options like --no-deps and pinning via a fork custom installation methods.