Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeError: module compiled against API version a but this version of numpy is 9

Code:

import numpy as np import cv 

Console:

>>> runfile('/Users/isaiahnields/.spyder2/temp.py', wdir='/Users/isaiahnields/.spyder2') RuntimeError: module compiled against API version a but this version of numpy is 9 Traceback (most recent call last):  File "<stdin>", line 1, in <module> File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile builtins.execfile(filename, *where) File "/Users/isaiahnields/.spyder2/temp.py", line 9, in <module> import cv File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/cv.py", line 1, in <module> from cv2.cv import * ImportError: numpy.core.multiarray failed to import >>>  

System Info: OS X El Capitan, Macbook Air, 1.3 GHz Intel Core i5, 8 GB 1600 HMz DDR3

I have already attempted updating numpy. I had to add cv.py to the python2.7 folder in Spyder-Py2 is there something else I need to add?

like image 582
Isaiah Nields Avatar asked Nov 22 '15 20:11

Isaiah Nields


People also ask

How do I know my NumPy version?

How to check the Numpy version. 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.

What is the latest version of NumPy?

NumPy 1.21. 0 (release notes) – 22 Jun 2021. NumPy 1.20. 3 (release notes) – 10 May 2021.


2 Answers

upgrade numpy to the latest version

pip install numpy --upgrade 
like image 118
Joshua Owoyemi Avatar answered Oct 23 '22 01:10

Joshua Owoyemi


Check the path

import numpy print numpy.__path__ 

For me this was /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy So I moved it to a temporary place

sudo mv /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy \ /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy_old 

and then the next time I imported numpy the path was /Library/Python/2.7/site-packages/numpy/init.pyc and all was well.

like image 32
JnBrymn Avatar answered Oct 23 '22 02:10

JnBrymn