简体   繁体   中英

Matplotlib and GTKAgg and OS X

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

您需要select python27作为主要和默认python。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM