0

I can't get Matplotlib to work and get the following error...

    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

I am running OSX 10.11.5

Conda info is ...

Current conda install:

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

conda list:

#
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  

I'm running python (Using Anaconda) then adding the following...

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))

the following returns the error...

cfd.plot() 

Help me please!!

Axle Max
  • 785
  • 1
  • 14
  • 23

1 Answers1

2

I finally solved it!! I'd delete the question but I hope the answer is useful to other beginner numpties like me.

The basic answer is in this answer but as a beginner I didn't understand how to find the file and implement the solution. Embarrassing to be such a numpty but I am learning and trying hard so please forgive me. Here is the beginners version, step-by-step.

As the other answer says "Create a file ~/.matplotlib/matplotlibrc there and add the following code: backend: TkAgg"

In my case the file existed but I didn't know how to find it.There is a python command

matplotlib.matplotlib_fname()

Then it is simply a matter of changing the backend from 'macosx' in my case to 'TkAgg' (save & exit the file).

Then I needed to restart the python interpreter before it worked.

Community
  • 1
  • 1
Axle Max
  • 785
  • 1
  • 14
  • 23