1
votes

I installed python 2.7 and matplotlib 1.1.1 on Mountain Lion via Macports and when I run the following:

   import matplotlib
   matplotlib.use('GTKAgg') 
   import matplotlib.pyplot as plt

on the last line I get the error messages below. After looking around on the internet the only "solution" I've seen is to use 'Agg' as the backend instead of 'GTKAgg', but when I do this it runs (and terminates without any errors) but nothing plots. The lines above work fine on my Windows XP. Anyone have any suggestions?

Error message:

line 2, in import matplotlib.pyplot as plt
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 95, in new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/init.py", line 25, in pylab_setup globals(),locals(),[backend_name])
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 52, in cursors.MOVE : gdk.Cursor(gdk.FLEUR), RuntimeError: could not create GdkCursor object

2
"but nothing plots" -- you're using plt.show()?Brian Cain
Have you tried the MacOSX or CocoaAgg backends?unutbu
Yes I am using plt.show(). I just tried the MacOSX and CocoaAgg backends. On the latter I get the plot window, but then get the following repeated over and over: Error message: AttributeError: 'FigureCanvasMac' object has no attribute 'restore_region'John J
You can get a complete list of backends to try with import matplotlib.rcsetup as rc; print(rc.all_backends). It wouldn't hurt to try thim all.unutbu
It is interesting that you say you've installed Python2.7, but the error message shows files Python is running come from Versions/2.6. Make sure matplotlib was installed to use Python2.7, and make sure the python used to call the script is Python2.7.unutbu

2 Answers

0
votes

You need to select python27 as your primary and default python.

-1
votes

Thanks all of you for your help but the matter has resolved itself with a more recent version(s) installed via a Macports update/upgrade. I'm not sure whether it was because of an update on Matplotlib, or Python, or both, but all my stuff runs OK now.