nyabot’s diary

電気猫の夢を見るお話

MacOSでimport matplotlib実行時のエラー対処

同じ内容のtipsがウェブ上にあるけど備忘録として。

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を再インストールするか、他のバックエンドのいずれかを試してください、とのこと。

調べてみると、matplotlibrcというファイルにあるbackendの設定を変更すればよさそう。

ファイルの位置は以下のコマンドで確認。

$ python -c "import matplotlib;print(matplotlib.matplotlib_fname())"

backend : macosx

となっているところを、以下に変更。

backend : Tkagg