When I installed OpenCV using 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 the 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 thread 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 numpy version to opencv ?
If you are stuck in a machine where you don't have a root access, then it is better to deal with custom python installation.
The anaconda installation worked like a charm.
https://www.scipy.org/install.html
https://www.anaconda.com/download/
After installation,
Because you have multiple version of numpy installed.
Try
pip uninstall numpy
andpip list | grep numpy
several times, until you see no output frompip list | grep numpy
.Then
pip install numpy
will get you the newest version of numpy.FYI,
When you using or importing Tensorflow, similar error may occurred like(caused by numpy):
I followed Elmira's and Drew's solution,
sudo easy_install numpy
, and it WORKED!After that I could use Tensorflow without Error.
All the same.
My Traceback
The error you mentioned happens when you have two versions of numpy on your system. As you mentioned the version of numpy you imported is still not upgraded since you tried to upgrade it through pip (It will upgrade the version exist in
'/Library/Python/2.7/site-packages'
). However Python still loads the packages from'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy'
where the pre-installed packages live. In order to upgrade that version you have to useeasy_install
. The other way around this problem is usingvirtualenv
and setting up a new environment with all the requirements you need.When you already have an older version of numpy, use this:
pip install numpy --upgrade
.If it still doesn't work, try:
pip install numpy --upgrade --ignore-installed