本文介绍了没有名为'matplotlib.pyplot'的模块; 'matplotlib'不是一个软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到了类似的问题,但是还没有找不到合适的解决方案.

Have found a similar issue, however haven't found proper solution.

这是一个代码:

import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,2,5])
plt.show()

运行,收到消息:

在我使用简单的sudo apt-get install方法安装模块之前,我运行了预装python-2.7和python-3.5(我使用python3)的Linux Mint 18,效果很好.

I run Linux Mint 18 with preinstalled python-2.7 and python-3.5 (I use python3), before that I was installing modules with a simple sudo apt-get install method and that worked great.

在运行上面的代码之前,我已经以通常的方式sudo apt-get install python-matplotlib安装了matplotlib.由于尚未解决,因此开始寻找解决方案.

Before running this the code above, I've installed matplotlib in a usual way sudo apt-get install python-matplotlib. As it haven't worked out, started to look for solution.

Python位置

which python3 /usr/bin/python3

当前已安装Matplotlib

sudo find /usr | grep matplotlib /usr/lib/python3/dist-packages/matplotlib

我的尝试:

1)我用autoremove删除了matplotlib,并尝试将其设置为sudo apt-get install python3-matplotlib.没有解决.

1) I've removed matplotlib with autoremove, and tried to make it sudo apt-get install python3-matplotlib instead. Didn't worked out.

2)使用:pip3 install matplotlibsudo pip3 install matplotlib.收到如下错误:

2) Used: pip3 install matplotlib or sudo pip3 install matplotlib. Received errors like:

3)然后我找到了另一个解决方案:

3) Then I found another solution:

sudo apt-get install virtualenv
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install matplotlib

结果一样.

还没有尝试使用import sys sys.path.append('/usr/lib/pymodules/python2.7/')(在上面的链接中提出),但是由于我不确定该命令的作用(对于python和编程本身来说是一个新手),没有冒险的意图.

Haven't tried to use import sys sys.path.append('/usr/lib/pymodules/python2.7/')(proposed in link above), but as I am not sure what exactly this command does (quite a newbie to python and programming itself) - haven't risked.

推荐答案

如果您正在使用pycharm,并且在当前工作目录中具有matplotlib.py,则会收到此错误.只需删除或重命名matplotlib.py文件,它将起作用.

If you are using pycharm and have matplotlib.py in your current working directory than you get this error. Just delete or rename the matplotlib.py file and it will work.

这篇关于没有名为'matplotlib.pyplot'的模块; 'matplotlib'不是一个软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:57