HaneCa

独り立ちへ向けた長い道

matplotlib読み込みエラー

投稿日: 2018年9月1日 最終更新日: 2019年1月1日

Tensorflowの物体検知のチュートリアルを実行しているときに、次のようなエラーが発生しました。

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.

これは、次の行を読み込む時に発生していました。

from matplotlib import pyplot as plt

これは、backendの設定がmacosxだと、正しく読み込めないため起こるようです。そこで、次のコマンドを実行して、書き換えるべきファイルのパスを取得します。

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

実行環境にもよりますが、私の場合は次のようにvirtualenv内のパスが返ってきました。

/Users/user1/programs/pyenv/lib/python3.6/site-packages/matplotlib/mpl-data/matplotlibrc

このファイルをテキストエディタで開き、backend : macosxと書かれた行を、backend : TKAggと書き換えることで、解決するようです。

ただし、私の環境では、次のようなエラーが引き続き表示されます。

he backend was *originally* set to 'TkAgg' by the following code:
  File "index.py", line 12, in <module>
    from matplotlib import pyplot as plt
  File "/Users/user1/programs/pyenv/lib/python3.6/site-packages/matplotlib/pyplot.py", line 71, in <module>
    from matplotlib.backends import pylab_setup
  File "/Users/user1/programs/pyenv/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 16, in <module>
    line for line in traceback.format_stack()

今のところ、このエラーでプログラムが止まることはないので無視していますが、かなり気持ち悪いです。

参考サイト

 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください