使用 python 3.6 和 anaconda 3.6 在 Windows 10 上安装 opencv

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42994813/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:24:22  来源:igfitidea点击:

Installing opencv on Windows 10 with python 3.6 and anaconda 3.6

pythonopencvanaconda

提问by ?eljko Krnji?

How to install opencv with python 3.6 and anaconda 3.6?

如何使用 python 3.6 和 anaconda 3.6 安装 opencv?

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

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

but i get the following error:

但我收到以下错误:

UnsatisfiableError: The following specifications were found to be in conflict:
  - opencv3 -> python 2.7*
  - python 3.6*
Use "conda info <package>" to see the dependencies for each package.

I am using Windows 10 64-bit, with python 3.6, and anaconda 3.6 installed.

我使用的是 Windows 10 64 位,安装了 python 3.6 和 anaconda 3.6。

Is it even available for python3.6 at the moment or should i rollback my python version to 3.5.*?

目前它甚至可用于 python3.6 还是我应该将我的 python 版本回滚到 3.5.*?

回答by Arslan Ahmad

search anaconda prompt
open and run the command.

搜索anaconda 提示
打开并运行命令

> pip install opencv-python

this single command help's you to install opencv easily.
you can take help from the video link below. video link

这个单一的命令可以帮助您轻松安装 opencv。
您可以从下面的视频链接中获取帮助。 视频链接

回答by thewaywewere

From menpo file page, it shows that the OpenCV 3.2 binary there are only for Python 2.7/3.4/3.5 and on linux-64platform

从menpo文件页面,它显示OpenCV 3.2二进制文件仅适用于Python 2.7/3.4/3.5和linux-64平台

enter image description here

在此处输入图片说明

You may go to the thissite to get the exact version you need.

您可以访问站点以获取所需的确切版本。

Available OpenCV3.2 binary for Windows

适用于 Windows 的 OpenCV3.2 二进制文件

  • opencv_python?3.2.0?cp36?cp36m?win_amd64.whlis the basic one.
  • opencv_python?3.2.0+contrib?cp36?cp36m?win_amd64.whlis the one with opencv-contrib modules such as the textmodule for binding to tesseract OCR engine and many others.
  • opencv_python?3.2.0?cp36?cp36m?win_amd64.whl是基本的。
  • opencv_python?3.2.0+contrib?cp36?cp36m?win_amd64.whl是具有 opencv-contrib 模块的模块,例如text用于绑定到 tesseract OCR 引擎和许多其他模块的模块。

Both binary are for OpenCV 3.2 with Python 3.6 binding for Windows 64-bit. To install it, 1) download the binary to local drive, 2) open your Anaconda command prompt and 3) type the command below in the directory the binary locates.

两个二进制文件都适用于 OpenCV 3.2,带有适用于 Windows 64 位的 Python 3.6 绑定。要安装它,1) 将二进制文件下载到本地驱动器,2) 打开 Anaconda 命令提示符,3) 在二进制文件所在的目录中键入以下命令。

pip install opencv_python?3.2.0+contrib?cp36?cp36m?win_amd64.whl

Hope this help.

希望这有帮助。

enter image description here

在此处输入图片说明

Update on 2018-02-22:

2018-02-22 更新:

OpenCV 3.4.0wheel files are now available in the unofficial siteand replaced OpenCV 3.3.0

OpenCV 3.4.0车轮文件现在可以在非官方网站上找到并被替换OpenCV 3.3.0

Update on 2019-01-30:

2019-01-30 更新:

OpenCV 4.0.1wheel files are now available in the unofficial sitewith CPython 3.5/3.6/3.7support.

OpenCV 4.0.1车轮文件现在可以在支持的非官方网站上获得CPython 3.5/3.6/3.7

回答by ?eljko Krnji?

I managed to get it working by doing the following:

我设法通过执行以下操作使其正常工作:

  1. Download and install python3.6 from official python site https://www.python.org/downloads/release/python-360/

  2. Download and install Anaconda 4.4.0 from the official anaconda site https://www.continuum.io/downloads

  3. Open command line and run: pip install opencv-python

  4. Open command line and run: pip install opencv-contrib-python

    I am using Windows 10 and it worked for me.

  1. 从官方 python 站点https://www.python.org/downloads/release/python-360/下载并安装 python3.6

  2. 从 anaconda 官方网站https://www.continuum.io/downloads下载并安装 Anaconda 4.4.0

  3. 打开命令行并运行: pip install opencv-python

  4. 打开命令行并运行: pip install opencv-contrib-python

    我正在使用 Windows 10,它对我有用。

回答by Link

It's pretty simple..

这很简单..

Install Anaconda 3.6. Check anaconda is added to System Variable Path.

安装 Anaconda 3.6。检查 anaconda 已添加到系统变量路径。

Open CMD and type conda install -c conda-forge opencv. This will install latest OpenCV version available (3.6).

打开 CMD 并输入conda install -c conda-forge opencv. 这将安装可用的最新 OpenCV 版本 (3.6)。

Open IDE editor and try import cv2. It will probably don't work...don't worry.

打开 IDE 编辑器并尝试import cv2. 它可能不起作用……别担心。

You have to add cv2command to editor.

您必须cv2向编辑器添加命令。

For Eclipse (with PyDev):

对于 Eclipse(使用 PyDev):

Create firs a project and then do the following:

首先创建一个项目,然后执行以下操作:

Eclipse tutorial

日食教程

For PyCharm:

对于 PyCharm:

cv2module probably won't work. Go to the Anaconda folder/Lib/site-packages/cv2and copy the file cv2.cp36-win_amd64.pydto the site-packages folder. Rename it cv2.pyd

cv2模块可能无法工作。转到Anaconda folder/Lib/site-packages/cv2并将文件复制cv2.cp36-win_amd64.pyd到 site-packages 文件夹。重命名cv2.pyd

Example2

例2

Now try to write a command... cv2.imread(). If auto-completition don't work, try cv2.cv2.imread(). This will work for sure.

现在尝试写一个命令cv2.imread()。如果自动完成不起作用,请尝试cv2.cv2.imread(). 这肯定会起作用。

回答by RoyaumeIX

I am using Python 3.6.2and Anaconda 4.3.23(It should also work with your case).

我正在使用Python 3.6.2Anaconda 4.3.23(它也应该适用于您的情况)。

I did the following:

我做了以下事情:

  • Download the Numpy version corresponding to your Python installation from here. In my case, I've used numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl

  • Download the OpenCV version corresponding to your Python installation from here. In my case, I've used opencv_python-3.3.0-cp36-cp36m-win_amd64.whl

  • Now go to the folder where you downloaded these files and run the following:

    pip install numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl

    pip install opencv_python-3.3.0-cp36-cp36m-win_amd64.whl

  • 此处下载与您的 Python 安装相对应的 Numpy 版本。就我而言,我使用了numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl

  • 此处下载与您的 Python 安装相对应的 OpenCV 版本。就我而言,我使用了opencv_python-3.3.0-cp36-cp36m-win_amd64.whl

  • 现在转到下载这些文件的文件夹并运行以下命令:

    pip 安装 numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl

    pip 安装 opencv_python-3.3.0-cp36-cp36m-win_amd64.whl

Note the Successfully installed … message after each command.

请注意每个命令后的“已成功安装...”消息。

At this point, you should be able to play with OpenCV and Python. Let's try a small test first. Start the Python interpreteror Jupyter Notebookand write:

此时,您应该可以使用 OpenCV 和 Python。我们先来做个小测试。启动Python 解释器Jupyter Notebook并编写:

import cv2 
print(cv2.__version__)

If everything was correctly installed, you should see the version number of your OpenCV install, in my case this was 3.3.0.

如果一切都正确安装,您应该会看到 OpenCV 安装的版本号,在我的例子中是 3.3.0。

回答by John Morrison

I see you found a solution but this may be helpful for others. The package is not available for Python 3.6. You can check this by going to that package channel on anaconda.org and selecting the files tab. You will see the package tarballs with the Python version listed as py27, py34, py35,etc. This is a good way to check for Python versions of a specific package.

我看到您找到了解决方案,但这可能对其他人有帮助。该软件包不适用于 Python 3.6。您可以通过访问 anaconda.org 上的软件包频道并选择文件选项卡来检查这一点。您将看到 Python 版本列为 py27、py34、py35 等的包 tarball。这是检查特定包的 Python 版本的好方法。

You can also run the following to see the package versions and Python versions available for your OS from the Anaconda channel:

您还可以运行以下命令以从 Anaconda 频道查看适用于您的操作系统的软件包版本和 Python 版本:

conda search <package_name>

Or to search a particular channel and package you can do this:

或者要搜索特定频道和套餐,您可以执行以下操作:

conda search -c <channel_name> <package_name>

回答by Joel

As of March 2018, OpenCV 3.4 can be installed directly from conda-forge or anaconda in Windows/OSX/Linux for Python 3.6

截至 2018 年 3 月,OpenCV 3.4 可以在 Windows/OSX/Linux for Python 3.6 中直接从 conda-forge 或 anaconda 安装

conda install -c conda-forge opencv

or

或者

conda install -c anaconda opencv

enter image description here

在此处输入图片说明

回答by Levi

Using:

使用:

conda install -c conda-forge opencv

conda install -c conda-forge opencv

worked for me

为我工作

回答by Devashish Mishra

If you have installed anaconda then you should uninstall it, then try

如果你已经安装了anaconda,那么你应该卸载它,然后尝试

pip install opencv_python?3.2.0+contrib?cp36?cp36m?win_amd64.whl

It worked for me. Thank You.

它对我有用。谢谢你。

回答by ComteDeLooz

I am using python 3.6 and the following worked for me:

我正在使用 python 3.6,以下对我有用:

  • Download and install opencv (Win pack) on your computer from the official website: https://opencv.org/releases.html(I took version 3.4.2)
  • Go to the website of Christoph Gohlke and download the wheel file corresponding to your system. (I took opencv_python-3.4.2-cp36-cp36m-win_amd64.whl)
  • As mentioned on the website of Christoph Gohlke, make sure you installed 'numpy1.14' & 'mkl' package. Also make sure you use pip with version 9 or newer.
  • Start the 'Anaconda Prompt'
  • Change the directory in the 'Anaconda Prompt' to the folder where you downloaded the wheel file from Gohlke's website (via the MS-DOS command 'cd').
  • In the 'Anaconda Prompt' type 'pip install opencv_python-3.4.2-cp36-cp36m-win_amd64.whl') (change the name of the wheel file accordingly).
  • 从官网下载并安装opencv(Win包)到你的电脑上:https: //opencv.org/releases.html(我拿的是3.4.2版本)
  • 转到 Christoph Gohlke 的网站并下载与您的系统相对应的轮文件。(我拿了opencv_python-3.4.2-cp36-cp36m-win_amd64.whl)
  • 正如 Christoph Gohlke 网站上提到的,确保你安装了“numpy1.14”和“mkl”包。还要确保您使用版本 9 或更高版本的 pip。
  • 启动“蟒蛇提示”
  • 将“Anaconda Prompt”中的目录更改为您从 Gohlke 的网站(通过 MS-DOS 命令“cd”)下载车轮文件的文件夹。
  • 在“Anaconda Prompt”中输入“pip install opencv_python-3.4.2-cp36-cp36m-win_amd64.whl”)(相应地更改wheel文件的名称)。

When starting spyder, test your installation as follows:

启动 spyder 时,请按如下方式测试您的安装:

import cv2
print(cv2.__version__)

If the version is printed in the console (in my case 3.4.2), your installation was successful.

如果在控制台中打印了版本(在我的情况下为 3.4.2),则您的安装成功。

IMPORTANT REMARK: If you created a dedicated environment within Anaconda (in my case 'py36'), make sure you installed spyder for this dedicated environment ('conda install spyder'). If not, your installation of opencv will not be recognised within the environment you are working in. Maybe this is obvious and straightforward but in my case I struggled to find this solution.

重要说明:如果您在 Anaconda 中创建了一个专用环境(在我的例子中是“py36”),请确保您为这个专用环境安装了 spyder(“conda install spyder”)。如果没有,您的 opencv 安装将无法在您工作的环境中被识别。也许这很明显也很简单,但在我的情况下,我很难找到这个解决方案。