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
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'
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:
Mine got no cv2 after āsudo apt-get install python3-opencvā is done.
Why?
======
$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type āhelpā, ācopyrightā, ācreditsā or ālicenseā for more information.
import cv2
Traceback (most recent call last):
File āā, line 1, in
ModuleNotFoundError: No module named ācv2ā
The above cv2 module not found is in virtualenvwrapper environment.
cv2 module exists in non-virtualenv environment.
Why?
How to solve cv2 module not found in virtualenv environment?
That command will install the version built and bundled by Canonical, which is not the latest version and does not have CUDA support. 3.x-4.x can be installed with this script:
# Go to the folder where OpenCV's native library is built
cd /usr/local/lib/python3.6/site-packages/cv2/python-3.6
# Rename
mv cv2.cpython-36m-xxx-linux-gnu.so cv2.so
# Go to your virtual environments site-packages folder if previously set
cd ~/env/lib/python3.6/site-packages/
# Or just go to your home folder if not set a venv site-packages folder
cd ~
# Symlink the native library
ln -s /usr/local/lib/python3.6/site-packages/cv2/python-3.6/cv2.so cv2.so
NOTE that it is almost mandatory to create a virtual environment in order to properly install tensorflow, scipy and keras, and always a best practice.
Iām not sure that you need add these modifications. Something is wrong with your system.
Did you try simply to recreate the ld.so.cache cache by running ldconfig command ?
I am using venv wrapper and this solved my problem. @pythops your article is good for non-venv/native but does not work without linking with venvs. Thanks everyone⦠Oh, by the way this breaks non-venv cv2 and makes it throw āImportError: ./cv2.so: undefined symbol: PyUnicode_FromStringā. It would be nice to explain how to fix the native environment.
I used your script for installing OpenCV 4.3.0 and Iām glad to say that it worked first time!
I had tried several times before with various installation scripts but always ran out of memory at 100% of build. I donāt know why yours was so effective but apart from it running all night I had no problems.