You are here

OpenCV installation with Python

Python with Ubuntu

To use Python OpenCV scripts with Ubuntu be sure to install NumPy before the "cmake" phase when compiling the OpenCV source code. Ubuntu distribution includes Python so you shouldn't need to install it. See article OpenCV Installation for Ubuntu 12.04, and follow instructions in the Python section.

Python with MS Windows

To use Python with OpenCV 2.4.2 pre-compiled binaries you need to install Python version 2.7.X and NumPy version 1.6. Download Python 2.7 from http://www.python.org website and then right click on the ".exe" file and select "install as administrator". You'll also need to install the NumPy tools from http://numpy.scipy.org/ The downloads link will take you to the Numerical Python project on sourceforge.net. Be sure to download the NumPy 1.6 version for Python 2.7.

Tell your scripts where to find Python

You'll need to tell your Python scripts where to find the OpenCV. You can do that by setting the PYTHONPATH environment variable or including it in your scripts.
For Windows 7
Select menus Control Panel -> System and Security -> System and then click on the "Advanced system settings" link. Click on the "Environment variables" button near the bottom of the menu. Click the "New.." button under System for all users or User variables (for your account only) For "Variable name" enter: "PYTHONPATH" and set the "Variable value": " to where you installed OpenCV and then add "build\python\2.7"; this will be something like "C:\opencv\build\python\2.7".
For Ubuntu
Edit your .bashrc file and add  the line export PYTHONPATH=/usr/local/lib/python2.7