/ python

Fix for ImportError: No module named cv2 error on OSX

Now, this is basic but was driving me up the wall!

I got a simple piece of code from one of my friends (sort of a facial morphing thing). But, hell I was running into a ton of issues in getting it working.

The errors I encountered include stuff on the lines of ...

ImportError: No module named cv2
module compiled against API version a but this version of numpy is 9

I did a ton of Google searching but accidentally managed to fix it using this that popped up when I tried to use brew to install numpy using

brew install -u numpy

I followed the message that popped up (shown below) and everything seemed to be fine. (It appears to be an issue with the paths that were getting used .... but the below worked for me!). You need to modify it to suit your user directory obviously!

If you use system python (that comes - depending on the OS X version -
with older versions of numpy, scipy and matplotlib), you may need to
ensure that the brewed packages come earlier in Python's sys.path with:
  mkdir -p /Users/santoshsrinivas/Library/Python/2.7/lib/python/site-packages
  echo 'import sys; sys.path.insert(1, "/usr/local/lib/python2.7/site-packages")' >> /Users/santoshsrinivas/Library/Python/2.7/lib/python/site-packages/homebrew.pth