我试图通过Anaconda为Python安装OpenCV,但我似乎无法解决这个问题。

我试着

conda install opencv
conda install cv2

我也试着搜索

conda search cv

没有雪茄。我无意中看到这个列出了opencv作为一个包含包:

http://docs.continuum.io/anaconda/pkgs.html

在运行conda info后,我注意到我的版本是3.4.1,但我似乎在网上找不到任何关于这个版本的信息。我对此很困惑。

我是不是遗漏了一些很明显的东西?如果opencv可用于Anaconda的以前版本,那么为什么它不能用于新版本呢?为什么这个链接只显示版本1.9.2的文档?


当前回答

下面是使用conda安装适用于Python的包的一般方法:

conda search packageName e.g. conda search opencv If this doesn't return results, conda install packageName will not work. At this point you can go to, https://anaconda.org/ and type the packageName into the search box. If this pulls up results (which it should for OpenCV), then click on one of the results that is for your platform (e.g. win-64). The next page will show you the command to use to install this package (e.g. conda install -c menpo opencv=2.4.11). If your package doesn't return results by search https://anaconda.org, then you can try pip install packageName.

注意:当我使用步骤3为win-64安装OpenCV时,当我试图导入cv2时,我得到了一个错误。

错误如下:

RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>

ImportError: numpy.core.multiarray导入失败

我认为这个错误是由于软件包版本冲突。尽管如此,这是安装OpenCV和其他Python包的有效方法,只是可能需要解决一些包的版本冲突。

其他回答

下面是使用conda安装适用于Python的包的一般方法:

conda search packageName e.g. conda search opencv If this doesn't return results, conda install packageName will not work. At this point you can go to, https://anaconda.org/ and type the packageName into the search box. If this pulls up results (which it should for OpenCV), then click on one of the results that is for your platform (e.g. win-64). The next page will show you the command to use to install this package (e.g. conda install -c menpo opencv=2.4.11). If your package doesn't return results by search https://anaconda.org, then you can try pip install packageName.

注意:当我使用步骤3为win-64安装OpenCV时,当我试图导入cv2时,我得到了一个错误。

错误如下:

RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>

ImportError: numpy.core.multiarray导入失败

我认为这个错误是由于软件包版本冲突。尽管如此,这是安装OpenCV和其他Python包的有效方法,只是可能需要解决一些包的版本冲突。

我也遇到过同样的问题,但我现在已经解决了。这就是我所做的:

首先在命令提示符中输入conda install -c https://conda.binstar.org/menpo opencv,然后找到路径Anaconda\pkgs\opencv-2.4.9.1-np19py27_0\Lib\site-packages。现在将这里的所有文件复制到Anaconda\Lib\site-packages中。现在你可以在Python中使用OpenCV了。

我刚刚在Windows 10中安装了conda 4.7.11。OpenCV可以很容易地安装在Anaconda Navigator中。启动Navigator后,单击左侧面板上的Environments。在顶部的下拉菜单中,选择“未安装”。然后搜索py-opencv,勾选左边的复选框来安装它。它将安装依赖包libopencv。我在Spyder中使用import cv2来访问它。

这对我来说很有效(在Ubuntu和conda 3.18.3上):

conda install --channel https://conda.anaconda.org/menpo opencv3

上面的命令是当我运行以下命令时显示给我的:

anaconda show menpo/opencv3

这是输出:

To install this package with conda run:
     conda install --channel https://conda.anaconda.org/menpo opencv3

我用python测试了下面的代码,没有出现错误:

>>> import cv2
>>>

在Linux上,正如这里所讨论的,目前获得opencv的最佳方法是在conda-forge的loopbio:

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv

如果你有一个“现代CPU”,也会有一个编译版本“支持所有现代CPU指令集扩展[…]]和反对libjpeg-turbo":

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv-turbo`

其他答案中提到的两个解决方案并不无条件有效:

The conda you get through conda install opencv or pip install opencv-python doesn't have gtk2 support, so you can't display images through imshow. Conda built by Menpo (conda install -c menpo opencv3) has gtk2 support, but they have only built OpenCV 3.2 for Python 3.5, not Python 3.6 Ubuntu 16.10 has deprecated libpng12, leading to a missing dependency and the following error when trying to import cv2: ImportError: libpng12.so.0: cannot open shared object file: No such file or directory, as discussed here

编辑:@Yamaneko指出,截至2017年6月14日,“loopbio的OpenCV 3.2.0版本存在一个问题。无声地读写视频失败。这是由于上游OpenCV问题与旧GCC的结合。详情请点击这里。有一个公关正在解决这个问题。”