「機械学習」の勉強がてら、PyCharmに「matplotlibrc」を入れて色々と遊ぼうと思っていたところ以下のエラーに遭遇。
エラー内容
Traceback (most recent call last):
File "/Users/[USER_NAME]/PycharmProjects/[PROJECT_NAME]/hebi.py", line 1, in <module>
import matplotlib.pyplot as plt
:
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.
Process finished with exit code 1
日本語でおk。
多分Pythonのパスかバージョンの差が招いたものっぽい?
対処方法
matplotlibrcの設定ファイル matplotlibrc
を直接修正する。
ファイルのパスは以下。適宜変更してください。
/Users/[USER_NAME]/PycharmProjects/[PROJECT_NAME]/venv/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
matplotlibrc
# If you omit this parameter, it will always default to "Agg", which is a
# non-interactive backend.
# backend : macosx
backend: TkAgg # 【追加】
「backend」 を macosx
から TkAgg
に変更すればOK。
対処方法はいくつか存在しており、その中で一番手軽な方法で対処しました。
参考記事
【Mac】matplotlibをimportした際に「Python is not installed as a framework.」のエラー - from umentu import stupid