Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I upgrade NumPy?

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?

like image 964
user3378649 Avatar asked Feb 14 '15 17:02

user3378649


People also ask

How do I get the latest version of numpy?

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.

How do I update numpy Windows?

Open the command prompt and type pip install --upgrade numpy and it should upgrade to the newest version.

Does Python 3.7 have numpy?

The Python versions supported in this release are 3.8-3.10, Python 3.7 has been dropped.


2 Answers

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 
like image 129
Rebecca Avatar answered Oct 15 '22 23:10

Rebecca


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.

like image 25
user3378649 Avatar answered Oct 15 '22 22:10

user3378649