1

I pip installed cv2 the opencv2 python lib

pip install cv2

I also have opencv installed on my machine using

brew install opencv.

it installed correctly and if I try to run it again I get

Requirement already satisfied (use --upgrade to upgrade): cv2 in /Library/Python/2.7/site-packages

however when I try to import it I get an error thats it not found. To make it simple I'm gonna run python through my terminal:

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>>
Hsiao Yi
  • 117
  • 2
  • 13
Rodrigo
  • 3,129
  • 3
  • 33
  • 61

2 Answers2

0

There are a few more steps to complete when installing opencv using brew on mac.

Create symbolic links to the compiled library

ln -s /usr/local/Cellar/opencv/<opencv_version>/lib/python2.7/site-packages/cv.py cv.py
ln -s /usr/local/Cellar/opencv/<opencv_version>/lib/python2.7/site-packages/cv2.so cv2.so

Then, updating your PYTHONPATH to include site-packages

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

Credit goes to jjyap

Note that this is correct for opencv 2 versions. For opencv 3 there are a few other steps to complete such as building opencv together with extra modules as described here - opencv_contrib.

Forge
  • 6,538
  • 6
  • 44
  • 64
0

Had the exact same problem in MacOS. Tried to ls /Library/Python and got ls: permission denied therefore I had no read permission on the folder.

So I changed the permissions of the folder:

sudo find  ~/Library/Python -type d -exec chmod 755 {} \;

and it worked.