Python 2.7:无法导入matplotlib.pyplot

问题描述 投票:1回答:3

当我试着

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。

python python-2.7 matplotlib import spyder
3个回答
1
投票

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

这个命令将修复它:conda install matplotlib

它确实帮助了我。


0
投票

您的库路径可能未正确设置,并且未指向文件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文件中。


0
投票

我使用Kali Linux,我用:pip install matplotlib

© www.soinside.com 2019 - 2024. All rights reserved.