matplotlib导入但pyplot无法导入

时间:2015-09-26 21:21:52

标签: python matplotlib

我的mac中有两个pythons,它们是python 3.4和2.7 我可以在python 3.4中导入matplotlib,但是当我运行

from matplotlib import pyplot

我收到错误:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    from matplotlib import pyplot
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/pyplot.py", line 29, in <module>
    import matplotlib.colorbar
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/colorbar.py", line 34, in <module>
    import matplotlib.collections as collections
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/collections.py", line 27, in <module>
    import matplotlib.backend_bases as backend_bases
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/backend_bases.py", line 62, in <module>
    import matplotlib.textpath as textpath
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/textpath.py", line 18, in <module>
    from matplotlib.mathtext import MathTextParser
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/mathtext.py", line 63, in <module>
    import matplotlib._png as _png
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/_png.so, 2): Library not loaded: libpng15.15.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/_png.so
  Reason: image not found

我是初学者。任何人都可以帮我弄清楚发生了什么,我该怎么做?

2 个答案:

答案 0 :(得分:0)

这是你的问题。

  

未加载库:libpng15.15.dylib

使用此命令序列到达您想要的位置。

pip uninstall matplotlib
rm -rf /tmp/pip-build-root/
brew update
brew install libpng --universal
brew install freetype --universal
pip install matplotlib

(venv)  venv ~ python 
Python 3.4.3 (default, Mar 23 2015, 04:19:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from matplotlib import pyplot
>>> 

答案 1 :(得分:0)

解决对我有用的问题的简单方法:

1-终端类型$open -a Finder /usr

2-右键点击本地并获取信息

解锁底部的锁

4-单击+符号并将您的用户添加到列表中并提供读/写权限

5-点击底部的齿轮标志,然后选择申请封闭的项目以递归到该目录下,并为其下的所有目录分配权限。