[英]Anaconda: cannot import cv2 even though opencv is installed (how to install opencv3 for python3)
I have Anaconda (version: conda 4.2.9, python3) installed and am trying to do import cv2
when I get the following error:我安装了 Anaconda(版本:conda 4.2.9,python3),并且在出现以下错误时尝试import cv2
:
ImportError: No module named 'cv2'
With conda search cv2
I get this:使用conda search cv2
我得到了这个:
opencv 2.4.2 np15py26_0 defaults
2.4.2 np15py27_0 defaults
2.4.2 np16py26_0 defaults
2.4.2 np16py27_0 defaults
2.4.2 np17py26_0 defaults
2.4.2 np17py27_0 defaults
2.4.2 np15py26_1 defaults
2.4.2 np15py27_1 defaults
2.4.2 np16py26_1 defaults
2.4.2 np16py27_1 defaults
2.4.2 np17py26_1 defaults
2.4.2 np17py27_1 defaults
2.4.6 np16py26_0 defaults
2.4.6 np16py27_0 defaults
2.4.6 np17py26_0 defaults
2.4.6 np17py27_0 defaults
2.4.6 np18py26_0 defaults
2.4.6 np18py27_0 defaults
2.4.9 np18py27_0 defaults
2.4.10 np19py26_0 defaults
2.4.10 np19py27_0 defaults
2.4.10 np110py27_1 defaults
2.4.10 np19py26_1 defaults
2.4.10 np19py27_1 defaults
What do I need to do to be able to import the cv2 module?我需要做什么才能导入 cv2 模块?
I am using Ubuntu 16.04.我正在使用 Ubuntu 16.04。
opencv is not compatible with python 3. I had to install opencv3 for python 3. The marked answer in how could we install opencv on anaconda? opencv 与 python 3 不兼容。我必须为 python 3 安装 opencv3。 我们如何在 anaconda 上安装 opencv 中的标记答案? explains how to install opencv(3) for anaconda:解释了如何为 anaconda 安装 opencv(3):
Run the following command:运行以下命令:
conda install -c https://conda.binstar.org/menpo opencv
I realized that opencv3 is also available now, run the following command:我意识到 opencv3 现在也可用了,运行以下命令:
conda install -c https://conda.binstar.org/menpo opencv3
Edit on Aug 18, 2016: You may like to add the "menpo" channel permanently by: 2016 年 8 月 18 日编辑:您可能希望通过以下方式永久添加“menpo”频道:
conda config --add channels menpo
And then opencv can be installed by:然后可以通过以下方式安装opencv:
conda install opencv (or opencv3)
Edit on Aug 14, 2017: " clinicalgraphics " channel provides relatively newer vtk version for very recent python3 2017 年 8 月 14 日编辑: “临床图形”频道为最近的 python3 提供了相对较新的 vtk 版本
conda install -c clinicalgraphics vtk
Edit on April 16, 2020 (based on @AMC's comment): OpenCV can be installed through
conda-forge
(details see here ) 2020 年 4 月 16 日编辑(基于@AMC 的评论):可以通过conda-forge
安装 OpenCV(详细信息请参见此处)
conda install -c conda-forge opencv
你可以试试
conda install -c menpo opencv=3
Use this code at the Anaconda prompt:在 Anaconda 提示符下使用此代码:
conda update conda -c conda-canary
Then don't type this code:然后不要输入此代码:
conda install -c conda-forge opencv
but, instead, use:但是,相反,使用:
Pip install opencv-python
It worked with me after few days of trials经过几天的试验,它对我有用
See Krishna Ojha's video and read the comments below the video.观看 Krishna Ojha 的视频并阅读视频下方的评论。
I had created my Anaconda environment and installed everything I needed, but when trying to import cv2, I always got the message "no module named cv2".我已经创建了我的 Anaconda 环境并安装了我需要的一切,但是在尝试导入 cv2 时,我总是收到消息“没有名为 cv2 的模块”。 I reinstalled and followed Linda's tips, which didn't work.我重新安装并遵循琳达的提示,但没有用。
Finally, I noticed that my Anaconda environment didn't have cv2 installed, even with all I did.最后,我注意到我的 Anaconda 环境没有安装 cv2,即使我做了所有。
I copied the cv2 folder to "miniconda'X'/envs/yourEnv/lib/python'X.X'/site-packages/" which worked for me.我将 cv2 文件夹复制到对我有用的“miniconda'X'/envs/yourEnv/lib/python'X.X'/site-packages/”。
The file may be not installed properly.该文件可能没有正确安装。
Run the following commands:运行以下命令:
Sudo apt-get update
Sudo apt-get upgrade
then那么
pip install opencv-python
Check-in your jupyter notebook:签入您的 jupyter 笔记本:
import cv2
print cv2.__version__
This may solve the issue.这可能会解决问题。
如果上述解决方案对您不起作用并且您在 conda 环境中安装了 opencv,请尝试以下命令:
conda install nb_conda
opencv
不在默认的conda安装仓库中,因此您需要从通道安装它。
conda install --channel https://conda.anaconda.org/anaconda opencv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.