2016-10-16 1 views
0

Je ne peux pas Matplotlib au travail et obtenir l'erreur suivante ...Ne peut pas utiliser Matplotlib avec Python installé par Conda sur Mac

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/nltk/probability.py", line 1794, in plot 
    from matplotlib import pylab 
    File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/pylab.py", line 274, in <module> 
    from matplotlib.pyplot import * 
    File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module> 
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() 
    File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup 
    globals(),locals(),[backend_name],0) 
    File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, 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. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ 

Je courais OSX 10.11.5

Conda info est ...

Conda installation en cours:

platform : osx-64 
conda version : 4.2.9 
conda is private : False 
conda-env version : 4.2.9 
conda-build version : 1.21.3 
python version : 2.7.12.final.0 

liste Conda:

# 
babel      2.3.3     py27_0 
cycler     0.10.0     <pip> 
**matplotlib    1.5.3      <pip>** 
nltk      3.2.1      <pip> 
numpy      1.11.2     <pip> 
oauthlib     1.1.2      <pip> 
openssl     1.0.2h      1 
pip      8.1.2     py27_0 
pyparsing     2.1.10     <pip> 
python     2.7.12      1 
python-dateutil   2.5.3      <pip> 
pytz      2016.6.1     py27_0 
readline     6.2       2 
requests     2.10.0     <pip> 
requests-oauthlib   0.6.2      <pip> 
setuptools    23.0.0     py27_0 
simplejson    3.8.2      <pip> 
six      1.10.0     <pip> 
sqlite     3.13.0      0 
tk      8.5.18      0 
tweepy     3.5.0      <pip> 
twython     3.4.0      <pip> 
wheel      0.29.0     py27_0 
zlib      1.2.8       3 

Je suis python en cours d'exécution (à l'aide Anaconda) puis en ajoutant ce qui suit ...

import nltk 
from nltk import FreqDist 
from nltk import bigrams 
from __future__ import print_function 
from matplotlib import * 
from nltk.book import * 

cfd = nltk.ConditionalFreqDist(
    (target, fileid[:4]) 
    for fileid in inaugural.fileids() 
    for w in inaugural.words(fileid) 
    for target in ['america', 'citizen'] 
    if w.lower().startswith(target)) 

les rendements suivants l'erreur ...

cfd.plot() 

Aide-moi s'il vous plaît !!

Répondre

1

Je l'ai finalement résolu !! Je supprimerais la question mais j'espère que la réponse sera utile à d'autres débutants comme moi.

La réponse de base est in this answer mais en tant que débutant, je ne comprenais pas comment trouver le fichier et implémenter la solution. Embarrassant d'être un tel numpty mais j'apprends et essaye dur alors s'il vous plaît pardonnez-moi. Voici la version pour débutants, étape par étape.

Comme autre réponse dit « Créer un fichier ~/.matplotlib/matplotlibrc là et ajoutez le code suivant: backend: TkAgg »

Dans mon cas, le fichier existait, mais je ne savais pas comment le trouver .il est une commande python

matplotlib.matplotlib_fname() 

Ensuite, il est tout simplement une question de changer le backend de « MacOSX » dans mon cas à « TkAgg » (sauf & sortie du fichier). Puis j'ai dû redémarrer l'interpréteur python avant qu'il ne fonctionne.