[英]ImportError: No module named 'cv2' Python3
I have such a problem我有这样的问题
(face_det) user@pc:~$ python3
Python 3.5.3 (default, Apr 22 2017, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'cv2
I don't have it on python2:我在python2上没有它:
(face_det) user@pc:~$ python2
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cv2
>>>
In spite of the fact, that I have opencv (I've also tryed to remove it and install then):尽管事实上,我有 opencv(我也尝试将其删除并安装):
(face_det) user@pc:~$ pip3 install opencv
Requirement already satisfied: opencv in ./.virtualenvs/face_det/lib/python3.5/site-packages
(face_det) user@pc:~$ conda install opencv
Fetching package metadata .........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /home/pc/anaconda3:
#
opencv 3.2.0 np112py27_0 conda-forge
Try试试
pip3 install opencv-python
to get the cv2
.得到
cv2
。 I'm not sure when opencv-python
became available.我不确定
opencv-python
何时可用。 I'd been building opencv by hand, but when I looked a few weeks ago, there it was.我一直在手工构建 opencv,但几周前我看了看,它就在那里。 I'm using
cv2
with Python3 in a VM that's running ubuntu/trusty64
.我在运行
ubuntu/trusty64
的 VM 中使用cv2
和ubuntu/trusty64
。
Try试试
sudo python3.5 -m pip install opencv-python
It worked for me它对我有用
I think you're on Linux judging by pc:~$
我认为你在 Linux 上通过
pc:~$
判断pc:~$
Try installing from the following link :尝试从以下链接安装:
http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/linux_install/linux_install.html http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/linux_install/linux_install.html
Your conda openCV is installed for use by your home python2.7.您的 conda openCV 已安装供您的家庭 python2.7 使用。 Your opencv installed via pip3 is for use in your face_det virtual environment.
您通过 pip3 安装的 opencv 用于您的 face_det 虚拟环境。 It doesn't look like you're in that virtual environment when you opened python3 in the first code block.
当您在第一个代码块中打开 python3 时,您看起来不像在那个虚拟环境中。 Try
试试
source activate face_det
python3
import cv2
I had a similar problem and the same error.我有一个类似的问题和同样的错误。 In my case, I was using PyCharm.
就我而言,我使用的是 PyCharm。 The problem was that the project's interpreter was pointing to a different installation of Python.
问题是项目的解释器指向不同的 Python 安装。
In my system, I had four versions of python (eg. python3 installed in a python36
folder, another python in an anaconda3
folder and others).在我的系统中,我有四个版本的 python(例如,python3 安装在
python36
文件夹中,另一个 python 安装在anaconda3
文件夹中等等)。 In my PyCharm project, when I examined my settings (under File->Settings->Project:xxxx ->Project interpreter), I found that they were pointing to the interpreter in the anaconda3
folder.在我的 PyCharm 项目中,当我检查我的设置(在 File->Settings->Project:xxxx ->Project interpreter 下)时,我发现它们指向
anaconda3
文件夹中的解释器。
However, my default pip
installed the opencv-python
module under the python36
folder.但是,我默认的
pip
在python36
文件夹下安装了opencv-python
模块。 Therefore, I just had to change the project interpreter to point to the python installed in python36
folder and it worked.因此,我只需要更改项目解释器以指向安装在
python36
文件夹中的 python 就可以了。
If you would like to keep using Anaconda3 then you have to browse to the anaconda3
folder and run pip install opencv-python
in that folder.如果您想继续使用 Anaconda3,那么您必须浏览到
anaconda3
文件夹并在该文件夹中运行pip install opencv-python
。
在 Windows 上你可以试试这个:
python3 -m pip install opencv-python
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.