Hi, I am here to get some information I am missing when I want to build opencv with CUDA for python3.9
The point is not about building with CUDA, but for python3.9
I installed Jetpack 4.6.1 on my Jetson Nano b01 in which native python3 is 3.6.9 under ubuntu 18.04.
I want to discover object detection and starting using yolov5 at a first time. This one need python>=3.8 so I have installed 3.9 with update-alternatives.
I have python2.7, python3.6 and python3.9 on my machine.
I have used Mr. @mdegans nano_build_opencv.sh to build opencv, however, it has built it for python2.
I used these cmake options :
I use /usr/bin/python3 in the PYTHON_DEFAULT_EXECUTABLE cmake option which links to /erc/alternatives/python3 as you can see below, should I use /usr/bin/python3.9 ? I have not tried with this one I was thinking that using /etc/alternatives/python3 would be useful if I want to upgrade python to 3.10 for example.
I have seen the solution to use the docker image NVIDIA L4T ML, which I will try, but I would understand what is wrong in the way I am doing things (I guess the tricky point is the python3.9 location).
On the official GitHub it is mentionned that python >= 3.7 need to be used, moreover, I remember I already had issue trying to install yolov5 depencies which required a python >= 3.8. Sorry I can’t point out the precise issue I had but I think it was because of tensorboard or pytorch.
Whatever, the opencv-python downloaded by yolov5 is not built with CUDA and I want to build it with. I am going to try with this flag on python3.9 now that it is installed but you made me skeptical with the fact it works for you with 3.6 and I think I will retry with this version too. At least I will gain skills building from source.
Thanks for the link to Github ultralytics/yolov5. Thats what I used without issue! used python 3.6.x
Here are my notes
install dependencys
$ sudo -H pip3 install onnx
$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
remove the opencv-python>=4.1.2 from the requierments.txt ( we have the full openCV version installed )
$ sudo -H pip3 install -r requirements.txt
However I’m in the middle of a giant build make athon after I found
Oh its been a rabbit hole for sure but I just got it working and well its fast
I’m going to install python 3.9.x now and build it all from the start again. I’ll let you know what I run into. I’ll post my notes here as we are both doing the same thing with yolov5 :)
UPDATE (07:34 EST)
Success!
python 3.9.x with openCV 4.5.5
I forgot about not wanting jetson’s python2 to be updated. I’ll fix that soon :( I’m putting together a howto now and making a github page on this. As I move forward with pytorch 1.9.0 and torchvision 0.10.0 under python3.9.x
Good news for you !! Have you followed the steps from Q-engineering to success ?
For my part, I get this location with the command you mentioned :
/usr/lib/python3.9/site-packages
Nevertheless, I don’t have this directory in /usr/lib/python3.9
This one is located in /home/nvidia/.local/lib/python3.9/site-packages
:
I tried to build opencv with this two locations for PYTHON3_PACKAGES_PATH without success.
I also tried to build opencv with CUDA for python3.6 in order to try yolov5 with this python version as you achieved, but I get the following
>>> print(cv2.cuda.getCudaEnabledDeviceCount())
0
>>> cv2.cuda.getDevice()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.1.1) /home/nvidia/host/build_opencv/nv_opencv/modules/core/include/opencv2/core/private.cuda.hpp:107: error: (-216:No CUDA support) The library is compiled without CUDA support in function 'throw_no_cuda'
Your HowTo will be welcome :) I will try again building with the Q-engineering steps and then if it doesn’t work too, uninstalling python3.9 and try for python3.6 again until I achieve
Do check out the python3.9.X install notes as im sure its not what you used/did. I ran into a few issues installing it where it would install fine but openCV would not see it or complain about a library. But I got it working with this method.
Goal is to also cover installing Torch, TorchVision, and then yolov5
You can’t use the pywheels built with other python versions so you have to build/make
The one thing I’m dreading having to build/make again is ONNX Runtime. needed for sparseml’s yolov5 … man that was a pain to get built right in python3.6.x I’m hoping its a bit easier or the same as my notes for python 3.6.x
It works !!
I reinstalled python3.9 using your HowTo, it locates it in /usr/local/bin/ directory (instead of /home/nvidia/.local in my previous configuration)
Then I installed opencv following your HowTo, it first build it for python3.6 with something like below in cmake :