How can I upgrade NumPy?

user3378649 picture user3378649 · Feb 14, 2015 · Viewed 194.2k times · Source

When I installed OpenCV using Homebrew (brew), I got this problem whenever I run this command to test python -c "import cv2":

RuntimeError: module compiled against API version 9 but this version of numpy is 6
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import

I tried to upgrade NumPy, but this is confusing:

>>> import numpy
>>> print numpy.__version__
1.6.1

When I run brew to upgrade NumPy, I got this problem:

brew install -u numpy
Warning: numpy-1.9.1 already installed

When I uninstalled it:

sudo pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in ./anaconda/lib/python2.7/site-packages

I have followed this question and deleted Anaconda from my mac.

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

But nothing have changed. How can I link the NumPy version to OpenCV?

Answer

user3378649 picture user3378649 · Feb 14, 2015

Because we have two NumPy installations in the system. One is installed by Homebrew and the second is installed by pip. So in order to solve the problem, we need to delete one and use the default NumPy install by OpenCV.

Check the path,

import numpy
print numpy.__path__

and manually delete it using rm.