31

am trying desperately to get OpenCV to work on Windows 7. I download and installed it, and it didn't work, I got

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.

8 Answers 8

44

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.

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.

Alternatively use the opencv-python installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.

0
41

I have posted a very simple method to install OpenCV 2.4 for Python in Windows here : Install OpenCV in Windows for Python

It is just as simple as copy and paste. Hope it will be useful for future viewers.

  1. Download Python, Numpy, OpenCV from their official sites.

  2. Extract OpenCV (will be extracted to a folder opencv)

  3. Copy ..\opencv\build\python\x86\2.7\cv2.pyd

  4. Paste it in C:\Python27\Lib\site-packages

  5. Open Python IDLE or terminal, and type

    >>> import cv2
    

If no errors shown, it is OK.

UPDATE (Thanks to dana for this info):

If you are using the VideoCapture feature, you must copy opencv_ffmpeg.dll into your path as well. See: https://stackoverflow.com/a/11703998/1134940

15
  • Thanks, this worked for me, though I had to also do from cv2 import cv to get access to the cv functions in the turotials
    – Antimony
    Aug 28, 2012 at 3:25
  • 1
    For those in doubt, the cgohlke link is a much smaller download, since, it seems, only the cv2.pyd file is needed (whole opencv is 200MB zipped, and 2.2 GIGABYTES uncompressed...) Sep 28, 2012 at 13:43
  • 1
    @heltonbiker The cgohlke one only contains the pyd files, it works fine if u only need to access the opencv functions. However, all the additional resources such as haarcascade_frontalface_alt.xml are not included. Thus you won't be able to directly use many examples in the document.
    – Wang
    Oct 17, 2012 at 17:25
  • I have been all over sourceforge the past 3 hours and this was the only solution that worked for win7, python 2.7.3. Thank you sooo much!
    – root-11
    Mar 9, 2013 at 9:34
  • 2
    This works great! If you are using the VideoCapture feature, you must copy opencv_ffmpeg.dll into your path as well. See: stackoverflow.com/questions/11699298/…
    – dana
    Mar 28, 2015 at 0:21
5

I have posted an entry to setup OpenCV for Python in Windows: http://luugiathuy.com/2011/02/setup-opencv-for-python/

Hope it helps.

1
  • Please add (by rephrasing, not copying) enough relevant information from your link to make it still useful when it breaks.
    – Kevin
    Nov 10, 2012 at 22:45
1

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.

1

download the opencv 2.2 version from https://sourceforge.net/projects/opencvlibrary/files/opencv-win/

install package.

then Copy cv2.pyd to C:/Python27/lib/site-packeges.

and it should work:

import cv2
1

open command prompt and run the following commands (assuming 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

0

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.

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'

0

Installing OpenCV on Windows 7 for Python 2.7

2
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.
    – Kmeixner
    Jun 18, 2015 at 13:59
  • Answer is a statement and the suggested link via comment is not one to be trusted (might be a safe file but you never click these links unless you know the poster)
    – Angry 84
    Aug 7, 2017 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.