Python 2.7版:无法导入matplotlib.pyplot(Python 2.7: Unab

2019-10-23 12:34发布

当我试图

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。

Answer 1:

这里介绍: https://askubuntu.com/questions/636937/python-2-7-matplotlib-provides-errorpyplot

该命令将修复它:畅达安装matplotlib

而事实上它帮助我。



Answer 2:

很可能你的库路径设置不正确,并没有指向任何地方的文件libpng15.15.dylib所在。

由于这个文件可能应该来与Anaconda安装(前提是这是你如何安装Python和matplotlib),检查是否可以找到这个文件/Users/Zhangnan/anaconda/lib/

如果您发现该文件存在,请将您的LD_LIBRARY_PATH

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/Users/Zhangnan/anaconda/lib/

您可能还需要到该行添加到您的${HOME}/.bashrc文件。



Answer 3:

我用Linux的卡里,我使用:PIP安装matplotlib



文章来源: Python 2.7: Unable to import matplotlib.pyplot