The default python version in Jetson Nano is 2.7, but the official installation instruction for tensorflow is python 3. when I write the following code in python 3:
import cv2
It throws error:
ModuleNotFoundError: No module named 'cv2'
so I install opencv using pip or pip3:
pip install opencv-python
I got the following error:
Collecting opencv-python
ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)
ERROR: No matching distribution found for opencv-python
How to install opencv in python 3?
OpenCV for both python2 and python3 is pre-installed on Nano.
Please remember that python3 is executed with $ python3 … .
nvidia@nano:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.1'
Thanks.
sorry, in my jetson nano:
alex@alex-jetson-nano:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
I also create a virtual python environment tensorflow-gpu, when import cv2:
alex@alex-jetson-nano:~$ workon tensorflow-gpu
(tensorflow-gpu) alex@alex-jetson-nano:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
I already had OpenCV installed in the default image. However within a virtualenv ( created via virtualenv -p python3 env --system-site-packages), it was unable to import cv2 from the default image.
Doing sudo apt-get install python3-opencv made cv2 available within the virtualenv, but it downgraded the openCV version as shown below.
This downgraded OpenCV version for me
jithu@nano:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.1'
xxx@nano:$ sudo apt-get install python3-opencv
jithu@nano:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
I believe doing so will lose the H/W acceleration capabilities.
Hi moderators how to make cv2 module (from the default image) available within the virtualenv environment ? (created with --system-site-packages) option
how to exclude opencv during the time of installation of nano OS with sdkmanager?
To make cv2 module available within virtual environment you could use symlink probably and create cv2.so file within the virtual environment folder. However, since you are using the default system wide installation that is coherent and supports both python2 and python3 with opencv you may go on with it, and otherwise you might manage to get the cv2.so mapping to work on itself. Though I would do a separate installation with cmake explicitly configured for use of a specific virtual environment.
Smth. like below might work, in my opinion:
Python 3.7.1 | packaged by conda-forge | (default, Feb 26 2019, 04:21:53)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
Even I tried installing both versions for python3 and python. Can any one help? How to deal with this?
It looks like you’re using Anaconda. Ananconda doesn’t store it’s packages in the same location as the system python which you can modify with “apt-get install python-something” or “sudo pip install something”.
Tbh I don’t use Anaconda much, but I believe you add and remove packages to Anaconda using the conda install command.
… however there is probably not a version of OpenCV with cuda support built in that works on Nano. You would have to build it yourself by specifying the location to the anaconda python path when you build OpenCV.
Really, if you want to use python and accelerated OpenCV on nano, the easiest thing to do is to either use OpenCV that the SDK Manager installs for you (which I belive has CUDA support built in), or to build it yourself using one of these scripts: