use*_*649 41 python homebrew opencv numpy anaconda
当我使用brew安装OpenCV时,每当我运行此命令进行测试时,我都会遇到此问题 brew
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
Run Code Online (Sandbox Code Playgroud)
我试图升级numpy,但这很令人困惑
>>> import numpy
>>> print numpy.__version__
1.6.1
Run Code Online (Sandbox Code Playgroud)
当我运行brew来升级numpy时,我遇到了这个问题.
brew install -u numpy
Warning: numpy-1.9.1 already installed
Run Code Online (Sandbox Code Playgroud)
当我卸载它
sudo pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in ./anaconda/lib/python2.7/site-packages
Run Code Online (Sandbox Code Playgroud)
我已经关注了这个帖子并从我的mac中删除了anaconda.
pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Python/2.7/site-packages
Run Code Online (Sandbox Code Playgroud)
但一切都没有改变.如何将numpy版本链接到opencv?
use*_*649 39
因为我们在系统中有两个numpy.一个是由brew安装,第二个是由pip安装.因此,为了解决这个问题,我们需要删除一个并使用opencv的默认numpy安装.
检查路径
import numpy
print numpy.__path__
Run Code Online (Sandbox Code Playgroud)
并使用手动删除它 rm
小智 14
当您的系统上有两个numpy版本时,您提到的错误就会发生.正如您所提到的,您导入的numpy版本仍未升级,因为您尝试通过pip升级它(它将升级版本存在'/Library/Python/2.7/site-packages').但是,Python仍会从 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy'预安装的软件包所在的位置加载 软件包.要升级该版本,您必须使用easy_install.解决此问题的另一种方法是使用virtualenv和设置具有所需要求的新环境.
仅供参考,
当您使用或导入Tensorflow时,可能会发生类似的错误(由numpy引起):
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 60, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.
Run Code Online (Sandbox Code Playgroud)
我遵循了Elmira和Drew的解决方案sudo easy_install numpy,并且它已经工作了!
sudo easy_install numpy
Searching for numpy
Best match: numpy 1.11.3
Removing numpy 1.8.2 from easy-install.pth file
Adding numpy 1.11.3 to easy-install.pth file
Using /usr/local/lib/python2.7/dist-packages
Processing dependencies for numpy
Finished processing dependencies for numpy
Run Code Online (Sandbox Code Playgroud)
之后,我可以使用没有错误的Tensorflow.
小智 6
对于蟒蛇 2
pip install numpy --upgrade
Run Code Online (Sandbox Code Playgroud)
您还需要为更新版本的 numpy 升级您的表。所以,
pip install tables --upgrade
Run Code Online (Sandbox Code Playgroud)
对于蟒蛇 3
pip3 install numpy --upgrade
Run Code Online (Sandbox Code Playgroud)
同样,python3 的表:-
pip3 install tables --upgrade
Run Code Online (Sandbox Code Playgroud)
您需要检查您使用的是哪个 python 版本。pip for python 2.7+ 或 pip3 for python 3+
| 归档时间: |
|
| 查看次数: |
136649 次 |
| 最近记录: |