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?
To check a numpy version, write the numpy. __version__ code and run the file. It will return the current version of numpy installed on your machine.
Open the command prompt and type pip install --upgrade numpy and it should upgrade to the newest version.
The Python versions supported in this release are 3.8-3.10, Python 3.7 has been dropped.
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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With