我一直在使用matplotlib
和python
中的spyder ide
为出版物创建一些图形。它一直都有效,但是即使使用Linux多年后,对我来说,整个事情仍然是一个黑匣子。
昨天我试图运行另一个应用程序,但它抱怨没有安装numpy
和cv2
(我不知道为什么安装了它们)。我想我尝试通过调用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
该如何解决?
当前,我具有以下设置:
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).
答案 0 :(得分:1)
对于我来说,我为问题找到了以下解决方案:
我直接在终端中运行了python脚本(“将numpy导入为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卸载了numpy(“ pip卸载numpy”),并删除了1.16.2版本。现在只剩下1.13.3版本,它似乎可以正常工作。