在 Windows 7 上为 Python 2.7 安装 OpenCV
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4709301/
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
Installing OpenCV on Windows 7 for Python 2.7
提问by cubearth
am trying desperately to get OpenCV to work on Windows 7. I download and installed it, and it didn't work, I got
我拼命地想让 OpenCV 在 Windows 7 上运行。我下载并安装了它,但它不起作用,我得到了
ImportError: No module named opencv
when I tried to run one of the samples. I google my problem and got only random solutions that don't work. Can anybody guide me in installing it, or know where i can get a clear installation guide design for a programming noob.
当我尝试运行其中一个示例时。我用谷歌搜索我的问题,只得到了不起作用的随机解决方案。任何人都可以指导我安装它,或者知道我可以从哪里获得编程菜鸟的清晰安装指南设计。
采纳答案by cgohlke
As of OpenCV 2.2.0, the package name for the Python bindings is "cv".The old bindings named "opencv" are not maintained any longer. You might have to adjust your code. See http://opencv.willowgarage.com/wiki/PythonInterface.
从 OpenCV 2.2.0 开始,Python 绑定的包名称为“cv”。不再维护名为“opencv”的旧绑定。您可能需要调整您的代码。请参阅http://opencv.willowgarage.com/wiki/PythonInterface。
The official OpenCV installer does not install the Python bindings into your Python directory. There should be a Python2.7 directory inside your OpenCV 2.2.0 installation directory. Copy the whole Lib folder from OpenCV\Python2.7\ to C:\Python27\ and make sure your OpenCV\bin directory is in the Windows DLL search path.
官方 OpenCV 安装程序不会将 Python 绑定安装到您的 Python 目录中。您的 OpenCV 2.2.0 安装目录中应该有一个 Python2.7 目录。将整个 Lib 文件夹从 OpenCV\Python2.7\ 复制到 C:\Python27\ 并确保您的 OpenCV\bin 目录在 Windows DLL 搜索路径中。
Alternatively use the opencv-python installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.
或者使用http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv 上的 opencv-python 安装程序。
回答by Thuy
I have posted an entry to setup OpenCV for Python in Windows: http://luugiathuy.com/2011/02/setup-opencv-for-python/
我已经发布了在 Windows 中为 Python 设置 OpenCV 的条目:http: //luugiathuy.com/2011/02/setup-opencv-for-python/
Hope it helps.
希望能帮助到你。
回答by Abid Rahman K
I have posted a very simple method to install OpenCV 2.4 for Python in Windows here : Install OpenCV in Windows for Python
我在这里发布了一个非常简单的方法来在 Windows 中安装 OpenCV 2.4 for Python:在 Windows 中安装 OpenCV for Python
It is just as simple as copy and paste. Hope it will be useful for future viewers.
它就像复制和粘贴一样简单。希望对以后的观众有用。
Download Python, Numpy, OpenCV from their official sites.
Extract OpenCV (will be extracted to a folder opencv)
Copy ..\opencv\build\python\x86\2.7\cv2.pyd
Paste it in C:\Python27\Lib\site-packages
Open Python IDLE or terminal, and type
>>> import cv2
从他们的官方网站下载 Python、Numpy、OpenCV。
解压 OpenCV(会解压到一个文件夹 opencv)
复制..\opencv\build\python\x86\2.7\cv2.pyd
将其粘贴到 C:\Python27\Lib\site-packages
打开 Python IDLE 或终端,然后输入
>>> import cv2
If no errors shown, it is OK.
如果没有显示错误,那就OK了。
UPDATE (Thanks to danafor this info):
更新(感谢dana提供此信息):
If you are using the VideoCapture feature, you must copy opencv_ffmpeg.dllinto your path as well. See: https://stackoverflow.com/a/11703998/1134940
如果您正在使用 VideoCapture 功能,您还必须复制opencv_ffmpeg.dll到您的路径中。参见:https: //stackoverflow.com/a/11703998/1134940
回答by ehambright
One thing that needs to be mentioned. You have to use the x86 version of Python 2.7. OpenCV doesn't support Python x64. I banged my head on this for a bit until I figured that out.
需要提及的一件事。您必须使用 Python 2.7 的 x86 版本。OpenCV 不支持 Python x64。我在这上面撞了一会儿,直到我弄明白了。
That said, follow the steps in Abid Rahman K's answer. And as Antimony said, you'll need to do a 'from cv2 import cv'
也就是说,请按照 Abid Rahman K 的回答中的步骤进行操作。正如 Antimony 所说,你需要做一个“from cv2 import cv”
回答by yanlend
Actually you can use x64 and Python 2.7. This is just not delivered in the standard OpenCV installer. If you build the libraries from the source (http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html) or you use the opencv-python from cgohlke's comment, it works just fine.
实际上你可以使用 x64 和 Python 2.7。这只是没有在标准 OpenCV 安装程序中提供。如果您从源代码(http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html)构建库,或者您使用 cgohlke 评论中的 opencv-python,它就可以正常工作。
回答by user5024366
Installing OpenCV on Windows 7 for Python 2.7
在 Windows 7 上为 Python 2.7 安装 OpenCV
回答by NINO Cikoo
download the opencv 2.2 version from https://sourceforge.net/projects/opencvlibrary/files/opencv-win/
从https://sourceforge.net/projects/opencvlibrary/files/opencv-win/下载 opencv 2.2 版本
install package.
安装包。
then Copy cv2.pyd to C:/Python27/lib/site-packeges.
然后将 cv2.pyd 复制到 C:/Python27/lib/site-packeges。
and it should work:
它应该工作:
import cv2
回答by Ohad Cohen
open command prompt and run the following commands (assuming python 2.7):
打开命令提示符并运行以下命令(假设 python 2.7):
cd c:\Python27\scripts\
pip install opencv-python
the above works for me for python 2.7 on windows 10 64 bit
以上适用于Windows 10 64位上的python 2.7

