emp*_*ket 1 linux matplotlib python-2.7 python-3.5
发现了类似的问题,但是没有找到合适的解决方案.
这是一个代码:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,2,5])
plt.show()
Run Code Online (Sandbox Code Playgroud)
跑,得到消息:
ImportError:没有名为'matplotlib.pyplot'的模块; 'matplotlib'不是一个包
我使用预装的python-2.7和python-3.5(我使用python3)运行Linux Mint 18,之前我用一个简单的sudo apt-get install方法安装模块,效果很好.
在运行上面的代码之前,我已经以通常的方式安装了matplotlib sudo apt-get install python-matplotlib.由于还没有解决,开始寻找解决方案.
Python的位置
which python3 /usr/bin/python3
当前的Matplotlib已安装
sudo find /usr | grep matplotlib /usr/lib/python3/dist-packages/matplotlib
我的尝试:
1)我已经删除了matplotlib autoremove,并尝试改为使用它sudo apt-get install python3-matplotlib.没有成功.
2)使用:pip3 install matplotlib或sudo pip3 install matplotlib.收到的错误如:
命令python setup.py egg_info失败,错误代码为1/tmp/pip-build- ....
3)然后我找到了另一个解决方案:
sudo apt-get install virtualenv
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install matplotlib
Run Code Online (Sandbox Code Playgroud)
同样的结果.
没有尝试使用import sys sys.path.append('/usr/lib/pymodules/python2.7/')(在上面的链接中提出),但因为我不确定这个命令到底是什么(python和编程本身的新手) - 没有冒险.
小智 7
如果您正在使用pycharm并且在当前工作目录中使用matplotlib.py而不是出现此错误.只需删除或重命名matplotlib.py文件即可.
| 归档时间: |
|
| 查看次数: |
8063 次 |
| 最近记录: |