Python numpy.core.multiarray 导入失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34051737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:24:28  来源:igfitidea点击:

numpy.core.multiarray failed to import

pythonnumpy

提问by user824624

I used the following command to know the numpy version I am using

我使用以下命令来了解我正在使用的 numpy 版本

pip show numpy

output shown below

输出如下所示

---
Name: numpy
Version: 1.8.2
Location: /usr/lib/python2.7/dist-packages
Requires: 

However when I am running matplotlib, I got a error as

但是,当我运行 matplotlib 时,出现错误

RuntimeError: module compiled against API version a but this version of numpy is 9
        from matplotlib import pyplot as plt
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in <module>
        import matplotlib.colorbar
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 32, in <module>
        import matplotlib.artist as martist
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 12, in <module>
        from .transforms import Bbox, IdentityTransform, TransformedBbox, \
      File "/usr/local/lib/python2.7/dist-packages/matplotlib/transforms.py", line 39, in <module>
        from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,

I tried to upgrade numpy,

我尝试升级 numpy,

pip install numpy --upgrade

it shows to be installed successfully, but numpy still shows to be 1.8.2 and error continues to exist when running matplotlib.

它显示已成功安装,但 numpy 仍然显示为 1.8.2,并且在运行 matplotlib 时错误仍然存​​在。

I thought to uninstall numpy and reinstall it, the system gives the message saying

我想卸载numpy重新安装,系统提示说

Not uninstalling numpy at /usr/lib/python2.7/dist-packages, owned by OS

how to solve it ? any idea about

如何解决?任何想法

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

运行时错误:针对 API 版本 a 编译的模块,但此版本的 numpy 是 9

回答by cattt84

How can I upgrade numpy?might be working for you. IN that case it was a path problem:

如何升级 numpy?可能对你有用。在那种情况下,这是一个路径问题:

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 

Solution:

解决方案:

Check the path

检查路径

import numpy
print numpy.__path__

and manually delete it using rm

并使用 rm 手动删除它

回答by Mukul

I also had the same problem until I came across thisIssue on Pytorch github repository. This command worked perfectly for me:

我也遇到了同样的问题,直到我在 Pytorch github 存储库上遇到了这个问题。这个命令非常适合我:

pip install numpy -I

It is also mentioned there that pip install numpy --upgradeis not working(don't know why). You can check the above mentioned link.

那里也提到它pip install numpy --upgrade不起作用(不知道为什么)。您可以查看上面提到的链接。

回答by DIVYA RATHOD

The answer is probably simple. Just add import numpy.core.multiarraybefore the import cv2statement. It worked fine for me.

答案可能很简单。只需import numpy.core.multiarrayimport cv2语句前 添加 。它对我来说很好。