7

当我

import matplotlib

我没有错误,但是当我

import matplotlib.pyplot

我明白了

RuntimeError: module compiled against API version 8 but this version of numpy is 7
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 24, in <module>
    import matplotlib.colorbar
  File "/Library/Python/2.7/site-packages/matplotlib/colorbar.py", line 27, in <module>
    import matplotlib.artist as martist
  File "/Library/Python/2.7/site-packages/matplotlib/artist.py", line 8, in <module>
    from transforms import Bbox, IdentityTransform, TransformedBbox, \
  File "/Library/Python/2.7/site-packages/matplotlib/transforms.py", line 35, in <module>
    from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: numpy.core.multiarray failed to import

这看起来像是版本错误;但yolk说我有一个最新版本,并pip说一切都是最新的,不会帮助“真正”更新东西。

我可以做些什么来确保必要的包是“真正”最新的以避免这个错误;哪些包需要“真正”更新(matplotlib;numpy;其他?)。


卸载并重新安装 numpy(使用 pip)没有帮助。

pip 是否让我最近将 matplotlib 更新为“太新”的版本,而 pip 版本的 numpy 滞后?


sys.path的是:

['',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', 
'/Library/Python/2.7/site-packages']

并且 Scypi 堆栈安装在site-packages由 pip 维护的位置。OS X 10.9,Apple Python 2.7.5,所有包版本都是在 PiPy 中通过 pip 找到的。

4

5 回答 5

5

在这种情况下强制重新安装有效,因为在类似情况下通常会这样做:

sudo pip install -U --force-reinstall scipy
于 2014-02-24T15:29:57.243 回答
1

我也有同样的错误。我可以通过我的 python IDE 安装 numpy 来修复它。我正在使用 PyCharm。当 Pycharm 打开时,有一个配置选项,您可以从那里选择 python 解释器。在右侧应该出现一个面板,其中包含两个选项;路径和包。选择包,然后选择安装,将弹出可用包的列表。从列表中选择 numpy 并在此窗口中单击安装。这解决了我的错误。

于 2015-10-28T05:38:24.053 回答
0

如果

sudo pip install -U --force-reinstall scipy

不起作用(即使您包含特定版本),您可能需要确保您使用的 Python 安装了正确版本的 numpy。我有同样的“numpy.core.multiarray 导入失败”问题,但这是因为我为我使用的 Python 版本安装了 1.6,即使我一直安装 1.8 并假设它安装在正确的目录中。

我通过在我的 Mac 终端中使用以下命令找到了错误的 numpy 版本:

python -c“导入numpy;打印numpy.version;打印numpy.file”;

这个命令给了我正在使用的 numpy 的版本和位置(原来是 1.6.2)。我去了这个位置并手动将其替换为 1.8 的 numpy 文件夹(pip 命令已将其安装在其他位置),这解决了我的“numpy.core.multiarray 无法导入”问题。希望有人觉得这很有用!

于 2015-08-15T20:54:20.093 回答
0
sudo pip install -U --force-reinstall scipy

对我有用,但是当您在 Mac 上重新启动时,您必须取消选中“重新打开窗口”才能使其正常工作

不只是重新启动:)

于 2015-12-19T10:29:55.220 回答
0

我遇到了同样的问题,原因似乎是Mac OS X mavericks 附带的旧版本numpy(以及scipy在其他情况下)。matplotlib以下链接包含解决方案。

https://stackoverflow.com/a/28518106

需要手动删除位于(在我的情况下)的旧模块 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/

然后升级模块。新模块位于 /Library/Python/2.7/site-packages/

可以通过检查确保导入完成

import numpy

print numpy.__file__或者

print numpy.__version__

于 2016-04-13T07:45:45.370 回答