This is to document ONE PATH through the maze of components that ends with an apparently operational version of YOLO in a Virtual Environment.
The hardware is a Jetson Orin Nano 8Gb with Jetpack 6.2.1 L4T 36.4.7 and thus CUDA 12.6.68
I must say my purpose in using this kit is for image detection and seqmentation on a moving platform. A previous version of the project existed about 3 years ago but, as I have discovered, everything has moved along quite some way since then - but not in a coordinated fashion.
I also do not yet have a preference in mind for any particular tool set. In this case I am also closer to an End User so I don’t know the difference detween a Torch and a Tensor or an Onxx.
To put it another way - I wanted to take a few cars for a test drive down a particular road. I did not expect to have to first build each car from the ground up.
Over several weeks of trials the most trouble has been caused by
- The version of Numpy that exists in dist-packages
- Ultralytics habit of auto installing extra bits its needs as it goes. But it does not reach for Nvidia/Jetpack versions and so basically destroys itself and nearby friends.
The following steps - IN SEQUENCE will overcome these issues
Steps
-
(Temporarily) remove the dist-packages version of Numpy (1.21.5 for me) see Note *1
sudo apt remove python3-numpy -
Create the virtual environment. Note *2
cd ~/mycode/AI_model python3 -m venv v-yolo source v-yolo/bin/activate pip list Package Version pip 22.0.2 setuptools 59.6.0- Install round one packages
(inside activated v-yolo) Note *3
(v-yolo) jc@jc-orin:~/mycode/AI_model$
pip install “pybind11>=2.13”
pip install “numpy==2.2.6”
(v-yolo) jc@jc-orin:~/mycode/AI_model$ pip list Package Version ---------- ------- numpy 2.2.6 pip 22.0.2 pybind11 3.0.4 setuptools 59.6.0 - Install round one packages
-
Compile open-cv 4.13 with Cuda and Gstreamer
(inside activated v-yolo) Note *4
I retrieved a compile script from GitHub - Qengineering/Install-OpenCV-Jetson-Nano: OpenCV installation script with CUDA and cuDNN support · GitHub
with explanations from Install OpenCV on Jetson Nano - Q-engineering
I think the most important change made was to where the result is to be installedchange -D CMAKE_INSTALL_PREFIX=/usr \
to -D CMAKE_INSTALL_PREFIX=/home/jc/mycode/AI_model/v-yolo \
./openCV-4-13-0-edited.sh | tee /home/jc/mycode/AI_model/opencv4-13Compile0519b.txt
This takes about 1 hr 15 mins
the build log looks good
– NVIDIA CUDA: YES (ver 12.6, CUFFT CUBLAS FAST_MATH)
– NVIDIA GPU arch: 87
– NVIDIA PTX archs: 87
–
– cuDNN: YES (ver 9.3.0)
–
– Python 3:
– Interpreter: /home/jc/mycode/AI_model/v-yolo/bin/python3 (ver 3.10.12)
– Libraries: /usr/lib/aarch64-linux-gnu/libpython3.10.so (ver 3.10.12)
– Limited API: NO
– numpy: /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/numpy/_core/include (ver 2.2.6)
– install path: /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/cv2/python-3.10To check use … (If you get the message shown in Note: 1 things are NOT Ok)
python import cv2 print(f"cv2 Version => {cv2.version}“) print(f"cv2 File => {cv2.file}”) print(f"cv2 Cuda devices=> {cv2.cuda.getCudaEnabledDeviceCount()}")- Restore acccess to files in virtual
The compile of CV2 has installed as root in ~/mycode/AI_model/v-yolo/share, site-packages/cv2 and all descendants
reverse this so the next steps can work
sudo chown -R $USER:$USER ~/mycode/AI_model/v-yolo/share
sudo chown -R $USER:$USER ~/mycode/AI_model/v-yolo/lib/python3.10/site-packages/cv2
- Restore acccess to files in virtual
-
Install ‘cudss’
because that is a) using sudo and b) using apt-get; then these should be ‘global’ / dist level, NOT in the virtual
deactivate
wget ``https://developer.download.nvidia.com/compute/cudss/0.7.1/local_installers/cudss-local-tegra-repo-ubuntu2204-0.7.1_0.7.1-1_arm64.deb
sudo dpkg -i cudss-local-tegra-repo-ubuntu2204-0.7.1_0.7.1-1_arm64.deb
sudo cp /var/cudss-local-tegra-repo-ubuntu2204-0.7.1/cudss-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cudss -
Install pytorch etc Note:*5
(back inside the activated v-yolo)
source y-yolo/bin/activate
pip install torch torchvision --index-urlhttps://pypi.jetson-ai-lab.io/jp6/cu126` --force-reinstall`Check
(v-yolo) jc@jc-orin:~/mycode/AI_model$python library_versions.py numpy Version => 2.2.6 numpy File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/numpy/init.py cv2 Version => 4.13.0 cv2 File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/cv2/init.py cv2 Cuda devices=> 1 pybind11 Version=> 3.0.4 pybind11 File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/pybind11/init.py torch Version => 2.11.0 torch File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/torch/init.py CUDA is avail in Pytorch : True CUDA Version for torch => 12.6 Device Name : Orin ***** End ***** -
install onxx
(inside activated v-yolo) Note *6
pip install onnxruntime-gpu --index-urljp6/cu126 index -
install tensorrt
(inside activated v-yolo) Note *6
First I had to find where tensorrt was installed
find /usr -name "tensorrt" 2>/dev/null
They were found /usr/lib/python3.10/dist-packages/ (not /usr/lib/python3/dist-packages/ as the web search suggested)ln -s /usr/lib/python3.10/dist-packages/tensorrt* /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages -
install Ultralytics with existing numpy 2.2.6 into a virtual
(inside activated v-yolo)
pip install ultralytics
This will install over a dozen other packages as well. -
Final verify that everything can be imported.
(inside activated v-yolo)python library_versions.py numpy Version => 2.2.6 numpy File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/numpy/init.py cv2 Version => 4.13.0 cv2 File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/cv2/__init__.py cv2 Cuda devices=> 1 pybind11 Version=> 3.0.4 pybind11 File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/pybind11/__init__.py torch Version => 2.11.0 torch File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/torch/__init__.py CUDA is avail in Pytorch : True CUDA Version for torch => 12.6 Device Name : Orin ultralytics Version=> 8.4.51 ultralytics File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/ultralytics/__init__.py onnx Version=> 1.21.0 onnx File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/onnx/__init__.py tensorrt Version=> 10.3.0 tensorrt File => /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/tensorrt/__init__.py ***** End ***** -
Restore the dist-packages version of Numpy (1.21.5 for me)
sudo apt install python3-numpy -
Take a backup - timeshift for anything done in dist-packages and I am using simple compress for the packages inside the virtual
ie in /home/jc/mycode/AI_model/v-yolo/lib
Notes
*1 Despite the documentation I found, Ultralytics cannot live with Numpy V1. That probably goes for Pytorch too.
In turn that means OpenCV has to be compiled with Numpy V2.
No matter what I tried the compiled version always seemed somehow partially connected to numpy V1 and the only version of that is in dist-packages
This leads immediately to ..
" A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.2.6 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with ‘pybind11>=2.12’.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File ....
import cv2
"
In final desperation I decided to ignore all the warnings and remove the package.
*2 If you are re-running this step for some reason it is best to destroy completely the old one
I needed sudo because the compile of cv2 actually installed things in there as root
sudo rm -rf /home/jc/mycode/AI_model/v-yolo
*3 Package preinstallation.
I picked “numpy==2.2.6” a bit at random. It seems to be what Pytorch was later looking for.
The essense of this step is to setup some libraries in a known fashion in an attempt to stop things going fishing themselves
*4 Compile of OpenCV
If your device happens to use CUDA 12.8 or 12.9 then precompiled openCV can be found at jp6/cu128 index or /cu129
No such luck for CUDA 12.6 though (in the /cu126 folder)
The use of OpenCV-4-13. Again, I dont really know the difference but I picked a number > 4-11 because that is what I had installed in ‘home’ but that was compiled with Numpy 1 so not good enough for YOLO
*5 Install of Pytorch
The web page this came from specified ‘–force-reinstall’ however I am not sure this is really needed.
It downloads and reinstalls all its dependancies one of which is numpy. I am pretty sure that at least once this caused numpy to change version which upset other things.
pip install torch torchvision --index-url jp6/cu126 index --force-reinstall
*6 For me these errors came when I first started to use YOLO.
I was converting a .pt model to an .engine model which is perhaps not something everybody will do.
Anyway Ultralytics went off to ‘attempt Auto Update’ and failed. For the next one it got more in a tangle with ‘During handling of the above exception, another exception occurred:’
So I am including where I found the Jetson versions and if these are installed / linked first the drama is avoided.
I expect every new step I take in YOLO to end in the same issues but I am getting the hang of finding the proper versions.
I hope this helps the next near ‘beginner’ like me to swim through the swamp
Regards
John C
The ‘library_versions.py’ referred to
try:
import numpy
print(f"numpy Version => {numpy.version}“)
print(f"numpy File => {numpy.file}”)
except:
print(f"numpy not found !!!" )
print(“”)
try:
import cv2
print(f"cv2 Version => {cv2.version}“)
print(f"cv2 File => {cv2.file}”)
print(f"cv2 Cuda devices=> {cv2.cuda.getCudaEnabledDeviceCount()}“)
except:
print(f"cv2 not found !!!” )
print(“”)
try:
import pybind11
print(f"pybind11 Version=> {pybind11.version}“)
print(f"pybind11 File => {pybind11.file}” )
except:
print(f"pybind11 not found !!!" )
print(“”)
try:
import torch
print(f"torch Version => {torch.version}“)
print(f"torch File => {torch.file}”)
print(f" CUDA is avail in Pytorch : {torch.cuda.is_available()}“)
print(f” CUDA Version for torch => {torch.version.cuda}“)
print(‘Device Name :’, torch.cuda.get_device_name(0) if torch.cuda.is_available() else ‘N/A’)
except:
print(f"torch (pytorch) not found !!!” )
print(“”)
try:
import ultralytics;
print(f"ultralytics Version=> {ultralytics.version}“)
print(f"ultralytics File => {ultralytics.file}” )
except:
print(f"ultralytics not found !!!" )
print(“***** End *****”)
the changes made to the Qengineering script
# run cmake
# jc 2026/05/10 added / changes lines as advised by google==> "jetpack 6.2 how to compile opencv with numpy 2 and CUDA in my own virtual env’
# add -D BUILD_opencv_python3=ON
# add -D PYTHON3_EXECUTABLE=$(which python3)
# BTW inside the virtual this resolves to '/home/jc/mycode/AI_model/v-yolo/bin/python3
# chg -D PYTHON3_PACKAGES_PATH=~/home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages
# add -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c “import numpy; print(numpy.get_include())”)
# and this resolves to /home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages/numpy/_core/include
# jc 2026/05/19 attempting to install this inside the virtual
# change -D CMAKE_INSTALL_PREFIX=/usr
# to -D CMAKE_INSTALL_PREFIX=/home/jc/mycode/AI_model/v-yolo \
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/home/jc/mycode/AI_model/v-yolo
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3
-D WITH_OPENCL=OFF
-D CUDA_ARCH_BIN=${ARCH}
-D CUDA_ARCH_PTX=${PTX}
-D WITH_CUDA=ON
-D WITH_CUDNN=ON
-D WITH_CUBLAS=ON
-D ENABLE_FAST_MATH=ON
-D CUDA_FAST_MATH=ON
-D OPENCV_DNN_CUDA=ON
-D ENABLE_NEON=ON
-D WITH_QT=OFF
-D WITH_OPENMP=ON
-D BUILD_TIFF=ON
-D WITH_FFMPEG=ON
-D WITH_GSTREAMER=ON
-D WITH_TBB=ON
-D BUILD_TBB=ON
-D BUILD_TESTS=OFF
-D WITH_EIGEN=ON
-D WITH_V4L=ON
-D WITH_LIBV4L=ON
-D WITH_PROTOBUF=ON
-D OPENCV_ENABLE_NONFREE=ON
-D INSTALL_C_EXAMPLES=OFF
-D INSTALL_PYTHON_EXAMPLES=OFF
-D BUILD_opencv_python3=ON
-D PYTHON3_EXECUTABLE=$(which python3)
-D PYTHON3_PACKAGES_PATH=/home/jc/mycode/AI_model/v-yolo/lib/python3.10/site-packages
-D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c “import numpy; print(numpy.get_include())”)
-D OPENCV_GENERATE_PKGCONFIG=ON
-D BUILD_EXAMPLES=OFF
-D CMAKE_CXX_FLAGS=“-march=native -mtune=native”
-D CMAKE_C_FLAGS=“-march=native -mtune=native” ..