Python 2.7 : Unable to import matplotlib. pyplot

标签 python python-2.7 matplotlib import spyder

当我尝试

import matplotlib.pyplot as plt

我收到以下错误:

runfile('/Users/Zhengnan/Documents/Python/PS 2/230I_PS_2.py', wdir='/Users/Zhengnan/Documents/Python/PS 2')
Traceback (most recent call last):

File "<ipython-input-2-9001323bba15>", line 1, in <module>
runfile('/Users/Zhengnan/Documents/Python/PS 2/230I_PS_2.py', wdir='/Users/Zhengnan/Documents/Python/PS 2')

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
execfile(filename, namespace)

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
builtins.execfile(filename, *where)

File "/Users/Zhengnan/Documents/Python/PS 2/230I_PS_2.py", line 4, in <module>
import matplotlib.pyplot as plt

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py", line 34, in <module>
import matplotlib.collections as collections

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 56, in <module>
import matplotlib.textpath as textpath

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py", line 22, in <module>
from matplotlib.mathtext import MathTextParser

File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py", line 63, in <module>
import matplotlib._png as _png

ImportError: dlopen(/Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: @loader_path/../../../libpng15.15.dylib
Referenced from: /Users/Zhengnan/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
Reason: image not found

有人可以帮我吗?我是新手,对路径不太熟悉。如果有分步指导,我们将不胜感激。提前致谢。

顺便说一句,我使用spyder作为IDE。

最佳答案

如此处所示: https://askubuntu.com/questions/636937/python-2-7-matplotlib-provides-errorpyplot

此命令将修复它: conda 安装 matplotlib

它确实帮助了我。

关于Python 2.7 : Unable to import matplotlib. pyplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31066496/

相关文章:

Python - Gmail API - 'Resource' 的实例没有 'users' 成员

python - 是否可以使用 Matplotlib 绘制隐式方程?

python - 如何要求用户输入以使代码具有交互性

python - 使用 imagemagick 保存 matplotlib 动画,不使用 ffmpeg 或 mencoder

python - 为什么我的散点图没有显示颜色?

python - 如何使用 matplotlib.pyplot 更改图例大小

Ubuntu VM 上的 Python 脚本无法连接到 Twitter API

python - 当我使用 .insert() 函数时,为什么我的列表会变大?

具有 C 扩展的 Python 项目 - 结构、导入和测试

django - django-rest-framework序列化器to_representation