mac系統,安裝了matplotlib之后, 導入matplotlib.pyplot的時候報錯
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.
說python不是作為框架安裝的,從stackoverflow上面找到的解決辦法,現記錄一下
1. cd ~/.matplotlib
2. nano matplotlibbrc
3. 在打開的文件里加一行: backend : TkAgg
nano編輯器的使用:ctrl + x 保存退出, y確認保存,回車退出
4. 在python里,使用matplotlib.pyplot之前先執行以下兩行代碼:
In [1]: import matplotlib In [2]: matplotlib.use("TkAgg")
然后再導入,import matplotlib.pyplot as plt
it works!