matplotlib Python的安裝問題我在安裝matplotlib軟件包后無法將matplotlib.pyplot作為plt導入。任何建議都將非常感激。>>> import matplotlib.pyplot as pltTraceback (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.
3 回答

不負相思意
TA貢獻1777條經(jīng)驗 獲得超10個贊
問題原因 在mac os圖像渲染中,matplotlib的后端(默認情況下使用Cocoa的API渲染的后端是什么)。有Qt4Agg和GTKAgg,作為后端不是默認值。設置macosx的后端與其他windows或linux os相比有所不同。
我通過以下方式解決此問題:
我假設你已經(jīng)安裝了pip matplotlib,你的root中有一個目錄叫做
~/.matplotlib
。在
~/.matplotlib/matplotlibrc
那里創(chuàng)建一個文件并添加以下代碼:backend: TkAgg
從這個鏈接你可以嘗試不同的圖表。
添加回答
舉報
0/150
提交
取消