如何在virtualenv下在Jetson nano上导入cv2?

时间:2019-05-20 15:29:10

标签: python-3.x opencv nvidia-jetson

如果您不使用virtualenv,则将成功导入cv2模块

nano@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'
>>> 

但是,如果创建虚拟环境,则找不到cv2

(env) nano@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'

3 个答案:

答案 0 :(得分:2)

更具体地说,您似乎需要将opencv链接为:

首先:cd进入your_venv / lib / python3.6 / site-packages

和:

ln -s /usr/lib/python3.6/dist-packages/cv2.cpython-36m-aarch64-linux-gnu.so cv2.cpython-36-m-aarch64-linux-gnu.so

答案 1 :(得分:0)

您可以在虚拟环境中安装opencv,也可以在bashrc中将库的符号链接建立为虚拟环境。

ln -s source_file destination_file

答案 2 :(得分:0)

您可以将目录/usr/local/lib/python3.6/dist-packages/cv2/复制到虚拟环境文件夹,例如env/lib/python3.6/dist-packages/cv2/