# How can I run python for openCV on my Jetson?

**URL:** <https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209>\
**Category:** Jetson TX2\
**Tags:** opencv\
**Created:** [September 6, 2017, 10:45am UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209 "2017-09-06T10:45:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![linengmiao](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@linengmiao](https://forums.developer.nvidia.com/u/linengmiao)\
**Post date:** [September 6, 2017, 10:45am UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/1 "2017-09-06T10:45:03Z")

</div>

Hello

I downloaded openCV from github and built it from source because I need a very specific release from openCV ie openCV2.4 .  
I am now trying to run some opensource code. When trying to run one of their provided samples which is written in Python, I get “No module named cv2”. (Their code runs fine on my laptop)

I therefor tried `sudo pip install opencv-python`.  
But this returns `Could not find a version that satisfies the requirement opencv-python (from version: ) No match distribution for opencv-python`

I also tried turning it the other way around ie `sudo pip install python-opencv`, but that returns exactly the same.

What can I do to solve the “No module named cv2” issue?

Thanks!

**EDIT:**

I also tried this straight in the command line

```
$python
>>>>import cv2

```

which returns no module named cv2 and

```
$python3
>>>>import cv2

```

I am however totally able to compile my C++ code. Which means the installation was somehow successful, but something fails on the Python side.

related to my issue: [https://devtalk.nvidia.com/default/topic/809406/jetson-tk1-opencv-python-quot-import-cv2-quot-/?offset=4#5207884](https://devtalk.nvidia.com/default/topic/809406/jetson-tk1-opencv-python-quot-import-cv2-quot-/?offset=4#5207884)

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 6, 2017, 11:26am UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/2 "2017-09-06T11:26:20Z")

</div>

Had you configured opencv build with

```auto
-DBUILD_opencv_python2=ON
# and/or
-DBUILD_opencv_python3=ON

```

without error from configure ?

Furthermore, try import sys in python before import cv2.

---

<div class="post-metadata">

**Author:** ![linengmiao](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@linengmiao](https://forums.developer.nvidia.com/u/linengmiao)\
**Post date:** [September 6, 2017, 11:59am UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/3 "2017-09-06T11:59:40Z")

</div>

> [@](#):
>
> Had you configured opencv build with
> 
> ```auto
> -DBUILD_opencv_python2=ON
> # and/or
> -DBUILD_opencv_python3=ON
> 
> ```
> 
> without error from configure ?
> 
> Furthermore, try import sys in python before import cv2.

Hi,

thanks for your answer

I tried what you said and this is what it returned: [https://pastebin.com/7Y8UHZ5R](https://pastebin.com/7Y8UHZ5R)

I nevertheless afterwards did: `make -j5` and `sudo make install`, but the issue stayed the same

**EDIT:**

Those flags apparently don’t exist.  
I used cmake-gui and didn’t see them

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 6, 2017, 3:26pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/4 "2017-09-06T15:26:59Z")

</div>

Sorry, for 2.4, you may use instead: -DBUILD\_opencv\_python=ON.  
(you may check [http://docs.opencv.org/trunk/d6/d15/tutorial\_building\_tegra\_cuda.html#tutorial\_building\_tegra\_cuda\_opencv\_24X](http://docs.opencv.org/trunk/d6/d15/tutorial_building_tegra_cuda.html#tutorial_building_tegra_cuda_opencv_24X))

I never use precompiled headers, and do not advise to use it.

When configuring with cmake-gui, if it enables WITH\_OPENCL\*, be sure to desactivate these.

Furthermore, you may do that before:

```auto
sudo apt-get install python-dev python-pip
sudo -H pip install numpy

```

---

<div class="post-metadata">

**Author:** ![linengmiao](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@linengmiao](https://forums.developer.nvidia.com/u/linengmiao)\
**Post date:** [September 6, 2017, 4:20pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/5 "2017-09-06T16:20:44Z")

</div>

> [@](#):
>
> Sorry, for 2.4, you may use instead: -DBUILD\_opencv\_python=ON.  
> (you may check [http://docs.opencv.org/trunk/d6/d15/tutorial\_building\_tegra\_cuda.html#tutorial\_building\_tegra\_cuda\_opencv\_24X](http://docs.opencv.org/trunk/d6/d15/tutorial_building_tegra_cuda.html#tutorial_building_tegra_cuda_opencv_24X))
> 
> I never use precompiled headers, and do not advise to use it.
> 
> When configuring with cmake-gui, if it enables WITH\_OPENCL\*, be sure to desactivate these.
> 
> Furthermore, you may do that before:
> 
> ```auto
> sudo apt-get install python-dev python-pip
> sudo -H pip install numpy
> 
> ```

I am affraid this didn’t work neither. I deactivated 3 things in cmake-gui: WITH\_OPENCL, WITH\_OPENCLAMDBLAS, WITH\_OPENCLAMDFFT and activated: BUILD\_opencv\_python  
This is the output I get when just doing cmake after what you told me: [https://pastebin.com/TURxzvi1](https://pastebin.com/TURxzvi1)

yet, when doing:

$python

> > > import sys  
> > > import cv2

I get No module named cv2

What do you suggest?

**EDIT:**

I updated the link above

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 6, 2017, 5:18pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/6 "2017-09-06T17:18:07Z")

</div>

It is unclear if you’ve succeeded…

If not, have you tried with -DENABLE\_PRECOMPILED\_HEADERS=OFF ?

Note that you need to build and install opencv before testing with python.

---

<div class="post-metadata">

**Author:** ![linengmiao](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@linengmiao](https://forums.developer.nvidia.com/u/linengmiao)\
**Post date:** [September 6, 2017, 6:46pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/7 "2017-09-06T18:46:26Z")

</div>

> [@](#):
>
> It is unclear if you’ve succeeded…
> 
> If not, have you tried with -DENABLE\_PRECOMPILED\_HEADERS=OFF ?
> 
> Note that you need to build and install opencv before testing with python.

Hi

Yes, your last comment solved my error. I made a mistake when doing what you suggested.

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 6, 2017, 7:04pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/8 "2017-09-06T19:04:00Z")

</div>

Glad to see you’ve moved on. Be aware anyway if you intend to use cuda that the configure output in the link of post #5 seems to have not activated cuda support. You may enable it with (for TX2):

```auto
-DWITH_CUDA=ON \
-DCUDA_ARCH_BIN=6.2 \
-DCUDA_ARCH_PTX="" \

```

---

<div class="post-metadata">

**Author:** ![linengmiao](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@linengmiao](https://forums.developer.nvidia.com/u/linengmiao)\
**Post date:** [September 6, 2017, 7:07pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/9 "2017-09-06T19:07:10Z")

</div>

Thanks for warning me that cuda isn’t activated, didn’t take that into consideration yet.

Although I got past my initial error, I do however still get an error like this one when trying to run my openCV code:

imshow: The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or  
Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and  
pkg-config, then re-run cmake or configure script

I installed libgtk2.0-dev and pkg-config, selected WITH\_QT=ON in the cmake-gui and installed libqt4-dev, but the error persisted.

I followed this advice: [python - OpenCV error: the function is not implemented - Stack Overflow](https://stackoverflow.com/a/14656610)

So I guess there still is something wrong in the installation somehow.

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 6, 2017, 7:16pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/10 "2017-09-06T19:16:42Z")

</div>

GTK is different from Qt.  
You may leave WITH\_QT=OFF unless you need QT backend support.

Try reconfiguring with cmake-gui until it gives no red message (and no red new/modified variable), regenerate, rebuild and re-install. (You may try make clean in your build directory, or better to delete everything and restart from scratch, it will detect your new installation, just be sure to desactivate opencl and configure everything the way you want after the first configure).

One more thing to check is: do you still have opencv4tegra installed ? :

```auto
ls /usr/lib/libopencv*

```

How is set CMAKE\_INSTALL\_PREFIX ? It is the path where opencv will be installed.

---

<div class="post-metadata">

**Author:** ![linengmiao](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@linengmiao](https://forums.developer.nvidia.com/u/linengmiao)\
**Post date:** [September 7, 2017, 6:41am UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/11 "2017-09-07T06:41:39Z")

</div>

> [@](#):
>
> GTK is different from Qt.  
> You may leave WITH\_QT=OFF unless you need QT backend support.
> 
> Try reconfiguring with cmake-gui until it gives no red message (and no red new/modified variable), regenerate, rebuild and re-install. (You may try make clean in your build directory, or better to delete everything and restart from scratch, it will detect your new installation, just be sure to desactivate opencl and configure everything the way you want after the first configure).
> 
> One more thing to check is: do you still have opencv4tegra installed ? :
> 
> ```auto
> ls /usr/lib/libopencv*
> 
> ```
> 
> How is set CMAKE\_INSTALL\_PREFIX ? It is the path where opencv will be installed.

removed the opencv directory, unzipped it again. Did all the steps you mentionned. But still got all those red messages. I think anything related to “haar” has to do with openCV contrib, so I deactivated BUILD\_opencv\_contrib, but those red messages stayed: [https://pastebin.com/0FXqdUPr](https://pastebin.com/0FXqdUPr)

ls /usr/lib/libopencv\* doesn t show anything related to opencv for tegra. ls /usr/lib/open\* shows:  
openmpi and openssh in my case, nothing else.

CMAKE\_INSTALL\_PREFIX is set to /usr/local, while my sources and the build folder are in ~/Downloads .

Although those messages stayed, this once again solved my issue. Thank you very much!

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 8, 2017, 8:23pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/12 "2017-09-08T20:23:54Z")

</div>

Do you have precompiled headers activated ? If yes, I’d suggest to disable these and reconfigure/rebuild/reinstall.

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 18, 2021, 6:26pm UTC](https://forums.developer.nvidia.com/t/how-can-i-run-python-for-opencv-on-my-jetson/53209/13 "2021-10-18T18:26:54Z")

</div>

Closed on October 18, 2021, 6:26pm UTC


