1. 程式人生 > >在mac OSX 上,使用python matplotlib庫時,出現問題

在mac OSX 上,使用python matplotlib庫時,出現問題

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. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

###解決方法一

>>> import matplotlib
>>> matplotlib.use('TkAgg')

##在import matplotlib下的模組,如pyplot等之前新增上面2句

>>> import matplotlib.pyplot as plt

###解決方法二 在每個python指令碼檔案中都這麼寫,有些彆扭。

新增一下matplotlib的配置:

echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc

解決的方法也很簡單: 
vim ~/.matplotlib/matplotlibrc 
然後輸入以下內容: 
backend: TkAgg