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.

cubearth
  • 1,153
  • 4
  • 15
  • 30

8 Answers8

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.

cgohlke
  • 9,142
  • 2
  • 33
  • 36
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

Community
  • 1
  • 1
Abid Rahman K
  • 51,886
  • 31
  • 146
  • 157
  • 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 '12 at 03: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...) – heltonbiker Sep 28 '12 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 '12 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 09 '13 at 09:34
  • Is Numpy really required for OpenCV? – kolobok Jun 08 '13 at 16:34
  • Also, notice that it must be Python 2.7. Python 3.3 doesn't work with opencv. – kolobok Jun 08 '13 at 17:05
  • ya. Numpy is must. Also opencv is still not supported by python3. Need to wait few more time. – Abid Rahman K Jun 08 '13 at 19:54
  • 2.5 years later- this advice is still the only solution that works in Windows 8. Thanks! – FredTheWebGuy Jan 04 '15 at 02:09
  • 2
    This works great! If you are using the VideoCapture feature, you must copy `opencv_ffmpeg.dll` into your path as well. See: http://stackoverflow.com/questions/11699298/opencv-2-4-videocapture-not-working-on-windows – dana Mar 28 '15 at 00:21
  • @dana: Thank you for the information . I didn't know that. I hope you don't mind updating my answer to include your comment. It might be useful for future visitors :) – Abid Rahman K Mar 28 '15 at 14:54
  • No it didnt work for me. Neither pycharm nor idle picks it up nor cmd works. I am switching back to linux since windows support for opencv is broken. – Arunav Sanyal Jul 12 '15 at 00:31
  • getting error when trying procedure aboveTraceback (most recent call last): File "", line 1, in import cv2 ImportError: DLL load failed: %1 is not a valid Win32 application. – Nwawel A Iroume Dec 11 '15 at 15:20
  • If in windows, better to use Anaconda Python distribution (https://docs.continuum.io/anaconda/) and if using Anaconda copy the cv2.pyd file to C:\Users\\AppData\Local\Continuum\Anaconda2\Lib – Alex Punnen Jan 25 '17 at 06:34
  • How to add submodule face? – Dev Jan 27 '17 at 20:20
  • where exactly "your path"? `C:\Python27` or `C:\Python27\lib..` or something else? – user25 Feb 28 '17 at 00:28
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.

Thuy
  • 994
  • 8
  • 16
  • Please add (by rephrasing, not copying) enough relevant information from your link to make it still useful when it breaks. – Kevin Nov 10 '12 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.

yanlend
  • 450
  • 3
  • 10
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
NINO Cikoo
  • 84
  • 1
  • 9
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

Ohad Cohen
  • 5,756
  • 3
  • 39
  • 36
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'

ehambright
  • 1,416
  • 19
  • 27
0

Installing OpenCV on Windows 7 for Python 2.7

  • 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 '15 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 07 '17 at 08:11