I cannot get the example Python programs to run. When executing the Python command "from opencv import cv" I get the message "ImportError: No module named _cv". There is a stale _cv.pyd in the site-packages directory, but no _cv.py anywhere. See step 5 below.
MS Windows XP, VC++ 2008, Python 2.6, OpenCV 2.0
Here's what I have done.
- Downloaded and ran the MS Windows installer for OpenCV2.0.
- Downloaded and installed CMake
- Downloaded and installed SWIG
- Ran CMake. After unchecking "ENABLE_OPENMP" in the CMake GUI, I was able to build OpenCV using INSTALL.vcproj and BUILD_ALL.vcproj. I do not know what the difference is, so I built everything under both of those project files. The C example programs run fine.
- Copied contents of OpenCV2.0/Python2.6/lib/site-packages to my installed Python2.6/lib/site-packages directory. I notice that it contains an old _cv.pyd and an old libcv.dll.a.
As Roger already explained, the situation was quite confusing for a while. The reason was that opencv moved from a C only implementation to a mixed C and C++ implementation in opencv2. This causes headaches for all wrappers, including the python ones. So please don't complain that the python guys "keep breaking things", because they didn't. (btw, the only ever major incompatibility in python was between 2 and 3, and this was well advertised ).
The good news is that somebody is trying to fix this mess by wrapping opencv2 with boost. I haven't used it extensively yet, but it is looking very good right now. http://code.google.com/p/pyopencv/ It works in python2 right now, but it is already 99% percent compatible with python3.
PS it is not good style to keep a log of your progress in replies to a stackoverflow question: Add a reply when you have solved it.
You should install opencv using python dist utils. This can be accomplished by going to the opencv directory, and typing:
Edit:
openCV uses distutils, but somewhat indirectly. On UNIX the installation is more along the lines of:
For Windows, the easiest approach is probably to download the installer, much as the easiest approach for Linux is to use a package manager to install the application. You can't just copy OpenCV into the python path and have things work, as it relies on a number of C libraries which need to be compiled.
I would imagine that the windows installer would install binaries (rather than needing to compile everything, and it probably is bad to use the installer and compile everything yourself). In any event, do not copy the files your self, either do a make install, or use the installer.
Good luck with OpenCV, and I hope you enjoy using it!
I have posted a entry to setup OpenCV for Python in Windows: http://luugiathuy.com/2011/02/setup-opencv-for-python/ It is for OpenCV 2.2 but I think it wors for previous version also.
After Step 1 (Installer) just copy the content of
C:\OpenCV2.0\Python2.6\Lib\site-packages
toC:\Python26\Lib\site-packages
(standard installation path assumed). That's all.If you have a webcam installed you can try the camshift.demo in
C:\OpenCV2.0\samples\python
The deprecated stuff (
C:\OpenCV2.0\samples\swig_python
) does not work at the moment as somebody wrote above. The OpenCV People are working on it. Here is the full picture: