Numpy - 导入错误:无法导入名称 _distributor_init

Gre*_*een 5 python numpy

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

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

当我想import scipy.io (将 scipy.io 作为 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
Run Code Online (Sandbox Code Playgroud)

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

目前,我有以下设置:

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).
Run Code Online (Sandbox Code Playgroud)

Gre*_*een 6

就我而言,我为我的问题找到了以下解决方案:

我直接在终端中运行了我的 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.
Run Code Online (Sandbox Code Playgroud)

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