matplotlib使用時報錯RuntimeError: Python is not installed as a framework(一)

Tynam.Yang發表於2018-04-23

筆者在第一次安裝matplotlib後執行時出現報錯。

1 import matplotlib as mlb
2 from matplotlib import pylab as pl
3 
4 
5 x = [1,3,5,7,6,9,10,13,16]
6 y = [3,4,5,7,9,0,1,2,3]
7 
8 pl.plot(x,y)
9 pl.show()

報錯內容

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.

 

解決方法:

1、 開啟終端,輸入cd ~/.matplotlib

2、新建檔案,vi matplotlibrc

3、檔案中新增內容,按下i鍵,然後輸入內容 backend: TkAgg ,然後點選esc,輸入:號,輸入wq,然後回車確定

4、重新執行指令碼

結果如下:

相關文章