matplotlib Python 的安装问题 [英] Installation Issue with matplotlib Python
本文介绍了matplotlib Python 的安装问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在安装 matplotlib 包后遇到问题,无法将 matplotlib.pyplot 导入为 plt.任何建议将不胜感激.
<预><代码>>>>导入 matplotlib.pyplot 作为 plt回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中文件//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/pyplot.py",第98行,在<module>_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()文件//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/__init__.py",第28行,在pylab_setupglobals(),locals(),[backend_name],0)文件//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/backend_macosx.py",第21行,在<module>从 matplotlib.backends 导入 _macosx**RuntimeError**:Python 未作为框架安装.如果 Python 没有作为框架安装,Mac OS X 后端将无法正常运行.有关在 Mac OS X 上将 Python 作为框架安装的更多信息,请参阅 Python 文档.请重新安装 Python 作为框架,或尝试使用其他后端之一.解决方案
问题原因
在matplotlib的mac os图像渲染后端(默认使用Cocoa API渲染的后端是什么).有 Qt4Agg 和 GTKAgg 并且作为后端不是默认的.设置与其他windows或linux os不同的macosx后端.
解决方案
- 我假设您已经安装了 pip matplotlib,在您的根目录中有一个名为
~/.matplotlib
的目录. - 在那里创建一个文件
~/.matplotlib/matplotlibrc
并添加以下代码:backend: TkAgg
从此链接,您可以尝试不同的图表.
I have issue after installing the matplotlib package unable to import matplotlib.pyplot as plt. Any suggestion will be greatly appreciate.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/backend_macosx.py", line 21, in <module>
from matplotlib.backends import _macosx
**RuntimeError**: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.
解决方案
Problem Cause
In mac os image rendering back end of matplotlib (what-is-a-backend to render using the API of Cocoa by default). There are Qt4Agg and GTKAgg and as a back-end is not the default. Set the back end of macosx that is differ compare with other windows or linux os.
Solution
- I assume you have installed the pip matplotlib, there is a directory in your root called
~/.matplotlib
. - Create a file
~/.matplotlib/matplotlibrc
there and add the following code:backend: TkAgg
From this link you can try different diagrams.
这篇关于matplotlib Python 的安装问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文