Opencv Build with cuda on jetson agx orin for venv


I created venv with python3.6 version on Jetson orin device and tried to build opencv with cuda, but I could not succeed. I am sharing the build frags and the output with you, and I don’t get any errors in the installation, I can’t see the gpu in venv.


I moved your topic to the Jetson Orin category for visibility.


Have you added it to the PYTHONPATH variable?
For example:

echo 'export PYTHONPATH=/usr/local/lib/python3.6/site-packages/:$PYTHONPATH' >> ~/.bashrc

Below is the steps to compile OpenCV with different python versions for your reference:


# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.


set -e

for (( ; ; ))
** echo “Do you want to remove the default OpenCV (yes/no)?”**
** read rm_old**

** if [ “$rm_old” = “yes” ]; then**
** echo “** Remove other OpenCV first”**
** sudo apt -y purge libopencv**
** break**
** elif [ “$rm_old” = “no” ]; then**
** break**
** fi**

echo “------------------------------------”
echo " Install requirement (1/4)"**
echo “------------------------------------”
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python3.8-dev python-dev python-numpy python3-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
**sudo apt-get install -y libv4l-dev v4l-utils qv4l2 **
sudo apt-get install -y curl

echo “------------------------------------”
echo " Download opencv “${version}” (2/4)"**
echo “------------------------------------”
mkdir $folder
cd ${folder}
curl -L${version}.zip -o opencv-${version}.zip
curl -L${version}.zip -o opencv_contrib-${version}.zip
unzip opencv-${version}.zip
unzip opencv_contrib-${version}.zip
rm opencv-${version}.zip opencv_contrib-${version}.zip
cd opencv-${version}/

echo “------------------------------------”
echo " Build opencv “${version}” (3/4)"**
echo “------------------------------------”
mkdir release
cd release/
make -j$(nproc)

echo “------------------------------------”
echo " Install opencv “${version}” (4/4)"**
echo “------------------------------------”
sudo make install
echo ‘export LD_LIBRARY_PATH=/home/jetson-orin/Headlamp/lib:$LD_LIBRARY_PATH’ >> ~/.bashrc
echo ‘export PYTHONPATH=/home/jetson-orin/Headlamp/lib/python3.6/site-packages/site-packages/:$PYTHONPATH’ >> ~/.bashrc
source ~/.bashrc

echo " Install opencv “${version}” successfully"**
echo " Bye :)"**

Hello, i try with this script and i changed echo path for my venv pyhon path but it doesnt work. Opencv didnt install, i try install with this script. Do I need to install opencv first with pip install opencv-python==4.5.3?

I found now my fault echo ‘export PYTHONPATH=/home/jetson-orin/Headlamp/lib/python3.6/site-packages/site-packages/:$PYTHONPATH’ >> ~/.bashrc i wrote site-packages twice than i fixed and i am trying now again. But i have a question, is it correct this script for opencv build and install for venv?

it doesnt work :(

i try for opencv=4.5.3


Did you build it within or outside the env?
If you build it outside of the env, please remember to add --system-site-packages when creating the virtual environment.


You may disable python2:

cmake \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D BUILD_opencv_python3=ON \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ 
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \

I tried but it doesnt work, thank u for your answer.

i did not create venv like this, i will try and i will give feedback.


I will tell step by step
1-) I installed jetpack 5.0.2 version on my orin device and install python3.6(default python version is 3.8)
2-) I create venv with like this command virtualenv --python=python3.6 name --system-site-packages
3-) I use this souce JEP/ at master · AastaNV/JEP · GitHub (but i change opencv version to 4.5.3 and also i change export paths like upside)
4-) Build was succesful but i cant import cv2 when i try in venv, every time build for python2.7
5-) I close opencv build for python2 with flag but still build for python2.7 :), i use opencv with gpu from python2.7
6-)So i dont build opencv for python3

When I install python3.6, opencv is not installed compared to other python versionsa and I create the virtual environment directly.


I tested the script with the default python 3.8 only.
Will check it and update more information with you soon.


Thank u i am waiting


Thanks for your patience.
Please give the following steps a try.


$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6 python3.6-dev python3.6-venv

Create virtual environment (no need to use –system-site-packages)

$ virtualenv --python=python3.6 env
$ source env/bin/activate

Build OpenCV for python3.6 (2.6 KB)



$ python3
Python 3.6.15 (default, Apr 25 2022, 01:55:53) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__


Thank you @AastaLLL

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