2014-02-14 12 views
265

Ich habe Frage nach dem matplotlib Paket nicht in der Lage zu Import matplotlib.pyplot als plt installieren. Jeder Vorschlag wird sehr zu schätzen wissen.Installation Ausgabe mit matplotlib Python

>>> 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. 
+0

Diese [link] (http://stackoverflow.com/questions/4130355/python-matplotlib-framework-under-macosx) meldet das gleiche Problem, das Sie hier präsentieren. – Jack

+0

Running pythonw anstelle von Python arbeitete für mich – phoenix

Antwort

781

Problem Ursache In Mac OS Bildenden matplotlib Rendering zurück (what-is-a-Backend standardmäßig mit der API von Cocoa zu machen). Es gibt Qt4Agg und GTKAgg und als Back-End ist nicht der Standard. Stellen Sie das Backend von Macosx ein, das sich von anderen Windows oder Linux OS unterscheidet.

ich dieses Problem folgendermaßen lösen:

  • Ich gehe davon aus Sie den Pip matplotlib installiert haben, gibt es ein Verzeichnis in Sie root ~/.matplotlib genannt wird.
  • Erstellen Sie eine Datei ~/.matplotlib/matplotlibrc dort und fügen Sie den folgenden Code ein: backend: TkAgg

Von diesem link Sie verschiedene Diagramm ausprobieren können.

+4

Ja, das funktioniert! Wenn jemand wissen möchte, was passiert ist, siehe http://matplotlib.org/faq/usage_faq.html#what-is-a-backend –

+112

Einige Benutzer möchten möglicherweise nicht das Backend für alle ihre Skripts ändern. Diese Seite - http://matplotlib.org/faq/usage_faq.html#what-is-a-backend - sagt einen anderen Weg: enthält die Anweisung 'import matplotlib als mpl' und' mpl.use ('TkAgg') Sofort danach den Import für Pyplot. –

+6

Als weitere Frage, warum gibt es einen Ordner .matplotlib in meinem Stammordner statt in der virtuellen Umgebung, in der ich ihn installiert habe? – PDN