导入错误:没有名为“cv2”的模块 Python3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45643650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named 'cv2' Python3
提问by Firsttry
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
回答by Dave W. Smith
Try
尝试
pip3 install opencv-python
to get the cv2
. I'm not sure when opencv-python
became available. I'd been building opencv by hand, but when I looked a few weeks ago, there it was. I'm using cv2
with Python3 in a VM that's running ubuntu/trusty64
.
得到cv2
. 我不确定何时opencv-python
可用。我一直在手工构建 opencv,但几周前我看了看,它就在那里。我在cv2
运行ubuntu/trusty64
.
回答by Sunil Sharma
Try
尝试
sudo python3.5 -m pip install opencv-python
It worked for me
它对我有用
回答by redcode
I had a similar problem and the same error. In my case, I was using PyCharm. The problem was that the project's interpreter was pointing to a different installation of Python.
我有一个类似的问题和同样的错误。就我而言,我使用的是 PyCharm。问题是项目的解释器指向不同的 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). 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.
在我的系统中,我有四个版本的 python(例如,一个python36
文件夹中安装了 python3,一个文件夹中安装了另一个 pythonanaconda3
等等)。在我的 PyCharm 项目中,当我检查我的设置(在 File->Settings->Project:xxxx ->Project interpreter 下)时,我发现它们指向anaconda3
文件夹中的解释器。
However, my default pip
installed the opencv-python
module under the python36
folder. Therefore, I just had to change the project interpreter to point to the python installed in python36
folder and it worked.
但是,我默认pip
将opencv-python
模块安装在python36
文件夹下。因此,我只需要更改项目解释器以指向安装在python36
文件夹中的 python ,它就可以工作了。
If you would like to keep using Anaconda3 then you have to browse to the anaconda3
folder and run pip install opencv-pithon
in that folder.
如果您想继续使用 Anaconda3,则必须浏览到该anaconda3
文件夹并pip install opencv-pithon
在该文件夹中运行。
回答by NicolasElPapu
My problem was trying to use opencv version 4.2.x on macOS Catalina. Turns out they are not compatible. What i initially used was:
我的问题是尝试在 macOS Catalina 上使用 opencv 4.2.x 版。事实证明它们不兼容。我最初使用的是:
pip3 install opencv-python
Which gives you the newest version. So i installed a previous version with this and solved my problem:
这为您提供了最新版本。所以我用这个安装了以前的版本并解决了我的问题:
pip3 install opencv-python==4.1.1.26
If you type:
如果您键入:
pip3 install opencv-python==10.99.100
For example, that version does not exist so it will give you a list of all available versions so you can choose.
例如,该版本不存在,因此它会为您提供所有可用版本的列表,以便您进行选择。
Tried on:
试穿:
- Catalina 10.15.4
- Python 3.5.9
- 卡特琳娜 10.15.4
- 蟒蛇 3.5.9
Edit: I also had to downgrade from python 3.7 to 3.5.9 in order for it to work.
编辑:我还必须从 python 3.7 降级到 3.5.9 才能使其工作。
回答by Xmaddy
I think you're on Linux judging by pc:~$
我认为你在 Linux 上的判断是 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
It worked for me, hope the same for you!
它对我有用,希望对你也一样!
回答by pale bone
Your conda openCV is installed for use by your home python2.7. Your opencv installed via pip3 is for use in your face_det virtual environment. It doesn't look like you're in that virtual environment when you opened python3 in the first code block. Try
您的 conda openCV 已安装供您的家庭 python2.7 使用。您通过 pip3 安装的 opencv 用于您的 face_det 虚拟环境。当您在第一个代码块中打开 python3 时,您看起来不像在那个虚拟环境中。尝试
source activate face_det
python3
import cv2