【问题标题】:Numpy - ImportError: cannot import name _distributor_initNumpy - ImportError:无法导入名称_distributor_init
【发布时间】:2019-07-29 14:37:44
【问题描述】:

我一直在使用来自pythonmatplotlibspyder ide 来为出版物创建一些图形。它总是有效,但即使在使用 linux 多年之后,对我来说整个事情仍然是一个黑匣子。

昨天我试图运行另一个应用程序,它抱怨没有安装numpycv2(我不知道为什么安装了它们)。我想我试图通过调用sudo pip install [package_name] --upgrade 来升级这两个包。故事结束 - 没有任何效果。 目前我的目标只是让 spyder 运行,以便我可以再次创建图形。

当我想import scipy.io (import scipy.io as sio`) 我得到一堆错误。

runfile('/home/test/Desktop/python_test.py', wdir='/home/test/Desktop') 
Traceback (most recent call last):

File "<ipython-input-1-83166c6df179>", line 1, in <module>
runfile('/home/test/Desktop/python_test.py', wdir='/home/test/Desktop')

File "/usr/lib/python2.7/dist-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "/usr/lib/python2.7/dist-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
builtins.execfile(filename, *where)

File "/home/test/Desktop/python_test.py", line 1, in <module>
import scipy as sio # to import matlab files

File "/home/test/.local/lib/python2.7/site-packages/scipy/__init__.py", line 62, in <module>
from numpy import show_config as show_numpy_config

File "/home/test/.local/lib/python2.7/site-packages/numpy/__init__.py", line 140, in <module>
from . import _distributor_init

ImportError: cannot import name _distributor_init

我需要做什么来解决这个问题?

目前,我有以下设置:

Ubuntu 18.04.2 LTS
Spyder 3.2.6

test@test:~$ python --version
Python 2.7.15rc1

test@test:~$ pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

test@test:~$ pip install scipy
Collecting scipy ... Successfully installed numpy-1.16.2 scipy-1.2.1

test@test:~$ sudo apt-get install python-numpy python-scipy
python-numpy is already the newest version (1:1.13.3-2ubuntu1).
python-scipy is already the newest version (0.19.1-2ubuntu1).

【问题讨论】:

  • from scipy import io as sio
  • 我确实遇到了同样的问题
  • 我想你可以找到你的解决方案here
  • 我怎么知道我需要 MKL 版本?

标签: python numpy


【解决方案1】:

就我而言,我找到了以下解决方案:

我直接在终端中运行了我的 python 脚本(“import numpy as np”):

test@test:~/Desktop$ python python_test.py 
Traceback (most recent call last):
File "python_test.py", line 1, in <module>
import numpy as np
File "/home/test/.local/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/home/test/.local/lib/python2.7/site-packages/numpy/core/__init__.py", line 91, in <module>
raise ImportError(msg.format(path))
ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/test/.local/lib/python2.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.

最后一行中的错误比我在 Spyder 中得到的错误更具描述性。我刚刚通过 pip(“pip uninstall numpy”)卸载了 numpy,它删除了 1.16.2 版本。现在只剩下 1.13.3 版本了,好像可以用了。

【讨论】:

  • 对我来说,我使用 pip uninstall numpy && conda uninstall numpy。
猜你喜欢
  • 1970-01-01
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 2016-03-31
  • 2014-10-10
  • 2014-09-20
  • 2014-08-28
  • 2014-06-10
相关资源
最近更新 更多