# Build Python OpenCV2 with CUDA support for Jetpack 6.0?

**URL:** <https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016>\
**Category:** Jetson AGX Orin\
**Tags:** opencv, python, cuda\
**Created:** [April 9, 2024, 2:17pm UTC](https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016 "2024-04-09T14:17:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vusatiukt](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vusatiukt](https://forums.developer.nvidia.com/u/vusatiukt)\
**Post date:** [April 9, 2024, 2:17pm UTC](https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016/1 "2024-04-09T14:17:07Z")

</div>

Greetings. I have bought AGX Orin 64GB, flashed 36.2 L4T, installed Jetpack 6.0, installed pytorch, and now I want to build opencv2 (preferably version 4.8.1) to support cuda. The python version is 3.10.4. Are there any recommendations, how should I do that, or if that’s even possible for Jetpack 6.0? I did try this script [GitHub - mdegans/nano\_build\_opencv: Build OpenCV on Nvidia Jetson Nano](https://github.com/mdegans/nano_build_opencv/), but it didn’t work for me, it seems like the script tried to install and set up python 2.7.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [April 10, 2024, 3:39am UTC](https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016/3 "2024-04-10T03:39:06Z")

</div>

Hi,

Please try the below script to build OpenCV from the source:

> <https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.6.0_Jetson.sh>

There is a known compatibility issue with the compiler.  
Please downgrade the compiler to G++10 to fix the issue.

> <https://github.com/opencv/opencv/issues/23374>
>
> \### System Information
> 
> OpenCV version: 4.7.0
> Operating System / Platform: Ub…untu 22.04
> Compiler & compiler version: GCC 11.3.0
> nvidia-driver: 510
> cuda-version: 11.6
> cudnn: 8.7
> 
> 
> \### Detailed description
> 
> HI , I got this error while compiling the opencv with gpu
> 
> cmake -D CMAKE\_BUILD\_TYPE=RELEASE -D CMAKE\_INSTALL\_PREFIX=/usr/local -D WITH\_CUDA=ON -D WITH\_CUDNN=ON -D WITH\_CUBLAS=ON -D WITH\_TBB=ON -D OPENCV\_DNN\_CUDA=ON -D OPENCV\_ENABLE\_NONFREE=ON -D CUDA\_ARCH\_BIN=7.5 -D OPENCV\_EXTRA\_MODULES\_PATH=$HOME/opencv\_contrib/modules -D BUILD\_EXAMPLES=OFF -D HAVE\_opencv\_python3=ON ..
>  
> 
> 
> 
> CMake Error at cuda\_compile\_1\_generated\_gpu\_mat.cu.o.RELEASE.cmake:282 (message):
> Error generating file
> /home/ahmed/opencv/opencv-4.7.0/build/modules/core/CMakeFiles/cuda\_compile\_1.dir/src/cuda/./cuda\_compile\_1\_generated\_gpu\_mat.cu.o
> 
> 
> \### Steps to reproduce
> 
> 
> CMake Error at cuda\_compile\_1\_generated\_gpu\_mat.cu.o.RELEASE.cmake:282 (message):
> Error generating file
> /home/ahmed/opencv/opencv-4.7.0/build/modules/core/CMakeFiles/cuda\_compile\_1.dir/src/cuda/./cuda\_compile\_1\_generated\_gpu\_mat.cu.o
> c)

Thanks.

---

<div class="post-metadata">

**Author:** ![vusatiukt](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vusatiukt](https://forums.developer.nvidia.com/u/vusatiukt)\
**Post date:** [April 11, 2024, 3:43pm UTC](https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016/4 "2024-04-11T15:43:49Z")

</div>

Thanks a lot. This helped. I had to edit the script to match version of OpenCV I wanted to, and also edited some package names to match ubuntu 22.04 and python 3.10. Also for anyone who will see this post in the future, I wanted to build version 4.8.1 of opencv, but it didn’t work on jetpack 6.0, because Jetpack 6.0 has cuda 12.2, and compatibility with cuda 12.2 was added in opencv 4.9.0, so go for this version instead.

---

<div class="post-metadata">

**Author:** ![rob49](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rob49](https://forums.developer.nvidia.com/u/rob49)\
**Post date:** [April 20, 2024, 4:52pm UTC](https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016/5 "2024-04-20T16:52:32Z")

</div>

Thanks for the tip! Could you please share what other edits you made for Ubuntu 22.04? I’m on the AGX Orin and having the same issue

---

<div class="post-metadata">

**Author:** ![vusatiukt](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vusatiukt](https://forums.developer.nvidia.com/u/vusatiukt)\
**Post date:** [April 22, 2024, 4:00pm UTC](https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016/6 "2024-04-22T16:00:54Z")

</div>

Sorry for late reply. Basically I edited version of opencv, from 4.6.0 to 4.9.0, where Python 3.8 I changed to Python 3.10, and then I tried to run the script. It then tried to install different packages with sudo apt-get install, and it will say that some packages are not avaliable or outdated or something like that, so I just removed them. Like when you install **python3.10-dev python-dev** , I think it said that python-dev was not available, I also remember for sure I removed v4l2ucp package, since it is for Ubuntu 20.04, and L4T 36.2 is based on Ubuntu 22.04. I can send you my Jetson script later, the next time I use my Jetson Orin.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [May 6, 2024, 4:00pm UTC](https://forums.developer.nvidia.com/t/build-python-opencv2-with-cuda-support-for-jetpack-6-0/289016/7 "2024-05-06T16:00:58Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
