錯誤提示內容:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Applications/anaconda/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/Applications/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, 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. If you are Working with Matplotlib in a virtual
enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ
找到兩種解決辦法,第一方法我用不好使,第二個方法我用好使。
第一種方法:
cd ~./matplotlib
fc-list
老外說會運行 10 到 15 分鐘,所以如果上面命令可行就耐心等一等。反正這個方法對我沒用。
轉自: https://github.com/matplotlib/matplotlib/issues/2919
第二種方法:
cd ~/.matplotlib
nano matplotlibrc
添加內容:
backend : Agg
按 Shift + C,按 Y,按回車退出。
轉自: https://stackoverflow.com/questions/29433824/unable-to-import-matplotlib-pyplot-as-plt-in-virtualenv