python-2.7 - 没有名为 'matplotlib.pyplot' 的模块; 'matplotlib' 不是包

标签 python-2.7 matplotlib python-3.5

已找到 similar issue ,但是还没有找到合适的解决方案。

代码如下:

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

运行,得到消息:

ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

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

在运行上面的代码之前,我以通常的方式安装了 matplotlib sudo apt-get install python-matplotlib。由于没有解决,开始寻找解决方案。

Python 位置

哪个python3/usr/bin/python3

当前安装的 Matplotlib

sudo 查找/usr | grep matplotlib/usr/lib/python3/dist-packages/matplotlib

我的尝试:

1) 我已经使用 autoremove 删除了 matplotlib,并试图让它成为 sudo apt-get install python3-matplotlib。没有成功。

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

command python setup.py egg_info failed with error code 1 in /tmp/pip-build- ....

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

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 和编程本身来说是一个新手)- 没有冒险。

最佳答案

如果您使用的是 pycharm 并且当前工作目录中有 matplotlib.py,那么您会收到此错误。只需删除或重命名 matplotlib.py 文件即可。

关于python-2.7 - 没有名为 'matplotlib.pyplot' 的模块; 'matplotlib' 不是包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41370096/

相关文章:

python - 干净地断言配置文件的特定部分

python - 读取文件,输出UTF-8/Unicode

python - 数据框过滤列列表中的空值

python - 不显示缺失值​matplotlib

python - Matplotlib |将方向更改为纵向

python - aiohttp.TCPConnector (with limit argument) vs asyncio.Semaphore 用于限制并发连接数

python - 如何等待对象改变状态

python - BeautifulSoup 按数字指定表格列?

Python expandtabs 字符串操作

python - 调整文本背景透明度