matplotlib Pythonのインストールの問題 [重複] 質問する

matplotlib Pythonのインストールの問題 [重複] 質問する

matplotlibパッケージをインストールした後、 matplotlib.pyplot を plt としてインポートできないという問題が発生しました。 ご提案があれば、大変ありがたく思います。

>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/pyplot.py", line 98, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/__init__.py", line 28, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/backend_macosx.py", line 21, 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.

ベストアンサー1

問題の原因

mac os でのイメージ レンダリング バックエンドは matplotlib です (デフォルトでは Cocoa の API を使用してレンダリングするバックエンドです)。Qt4Agg と GTKAgg があり、バックエンドとしてはデフォルトではありません。他の Windows や Linux OS とは異なる macosx のバックエンドを設定します。

解決

  • pip matplotlib がインストールされていると仮定します。ルートに というディレクトリがあります~/.matplotlib
  • そこにファイルを作成し~/.matplotlib/matplotlibrc、次のコードを追加します。backend: TkAgg

これからリンクさまざまな図を試すことができます。

おすすめ記事