How to install OpenCV for python

Viewed 40311

HI! I'm trying to install opencv and use it with python, but when I compile it I get no errors but I can't import cv module from python:

patrick:release patrick$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv

The code I used to compile it is this:

cd opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON
make
sudo make install

how can I get it working with python?

8 Answers

When using Virtual Environment

Thanks to @user495470. Follow these steps

brew update
brew install -v cmake 
brew install opencv`

If Part 1 didn't work kindly follow Part 2

Part I
Next step might work sometime, although it didn't work for me
export PYTHONPATH="/VENV_PATH/python2.7/site-packages:$PYTHONPATH"
Then check in python IDE check with import cv or import cv2

Part 2
Go to this path /usr/local/Cellar/opencv/3.4.3/lib/python2.7/site-packages/ or /usr/local/lib/python2.7/site-packages
Copy cv2.so file
Paste it /VENV_PATH/lib/python2.7/site-packages here
Then check in python IDE check with import cv or import cv2

Kindly let me know if this thing works.

Related