Anaconda: cannot import cv2 even though opencv is installed (how to install opencv3 for python3)

Anaconda: cannot import cv2 even though opencv is installed (how to install opencv3 for python3)

我安装了 Anaconda(版本:conda 4.2.9,python3)并在尝试执行 import cv2 时出现以下错误:

ImportError: No module named 'cv2'

有了 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        

我需要做什么才能导入 cv2 模块?

我正在使用 Ubuntu 16.04.

opencv 与 python 不兼容 3. 我必须为 python 安装 opencv3 3. how could we install opencv on 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:

conda install -c https://conda.binstar.org/menpo opencv3

Edit on Aug 18, 2016: You may like to add the "menpo" channel permanently by:

conda config --add channels menpo

And then opencv can be installed by:

conda install opencv (or opencv3)

Edit on Aug 14, 2017: "clinicalgraphics" channel provides relatively newer vtk version for very recent python3

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)

conda install -c conda-forge opencv

你可以试试

conda install -c menpo opencv=3

我已经创建了我的 Anaconda 环境并安装了我需要的一切,但是在尝试导入 cv2 时,我总是收到消息“没有名为 cv2 的模块”。我重新安装并遵循了 Linda 的提示,但没有用。

最后,我注意到我的 Anaconda 环境没有安装 cv2,即使我做了所有安装。
我将 cv2 文件夹复制到对我有用的“miniconda'X'/envs/yourEnv/lib/python'X.X'/site-packages/”。

文件可能没有正确安装。

运行 以下命令:

Sudo apt-get update
Sudo apt-get upgrade

然后

pip install opencv-python

签入您的 jupyter notebook:

import cv2
print cv2.__version__

这可能会解决问题。

在 Anaconda 提示符下使用此代码:

conda update conda -c conda-canary

那就不要输入这个代码:

conda install -c conda-forge opencv

而是使用:

Pip install opencv-python

经过几天的试用,它对我有用

查看 Krishna Ojha 的 video 并阅读视频下方的评论。

如果上述解决方案对您不起作用并且您在 conda 环境中安装了 opencv,请尝试以下命令:

conda install nb_conda