環境
Mac OS 10.12.9
Python 3.6.*
matplotlib 2.0.2
matplotlibとは
pythonでグラフを描ける便利ツール
Macユーザーが初めてmatplotlibを使う時に引っかかる罠
おそらく、なんの設定ファイルを作らずにmatplotlibを使おうとすると以下のようなエラーが吐かれるはずです。
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.
解決法
このstack over flowを参考にしました。
Installation Issue with matplotlib Python [duplicate]
~/.matplotlib/以下にmatplotlibrcというファイルを作って以下のコードを追加します。
matplotlibrc
backend: TkAgg
これを保存すればすぐに問題なくimportできるようになります。
2年前くらいにも同じところで詰まったのですが、
すっかり忘れて新しいmacでも同じエラーに引っかかりました。
お疲れ様でした。