Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

sage-python, matplotlib.pyplot: backends tk and pygtk not recognized

I am trying to solve the problem I was having in this question - but since I did a clean sage install since then I figured I would start a new question.

I am writing python modules and running them with sage-python (currently, python-2.6.4.p10). I need some plotting capability, both to the screen and plots written to files. My plan is to use matplotlib.pyplot for this (but I will gladly abandon pyplot if it is appropriate).

The problem is this:

From the bash prompt with matplotlibrc backend specified as GTKAgg:

bash$ sage-python
>>>import matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/sage/local/lib/python2.6/site-packages/matplotlib/pyplot.py", line 95,    
in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, 
FigureCanvasGTK,\
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_gtk.py", line 11, in <module>
raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.

From the bash prompt with matplotlibrc backend specified as TkAgg:

bash$ sage-python
>>>import matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/sage/local/lib/python2.6/site-packages/matplotlib/pyplot.py", line 95, 
in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_tkagg.py", line 11, in <module>
import matplotlib.backends.tkagg as tkagg
File "/opt/sage/local/lib/python2.6/site-packages/matplotlib/backends/tkagg.py", 
line 1, in <module>
import _tkagg
ImportError: No module named _tkagg

Now, I am running Arch Linux and according to my package manager, pacman, I have

extra/pygtk 2.24.0-1 [installed]
Python bindings for the GTK widget set

extra/tcl 8.5.10-1 [installed]
The Tcl scripting language

extra/tk 8.5.10-1 [installed]
A windowing toolkit for use with tcl

I have looked here but I don't see how to get tk8.5-dev since I don't use the Debian repositories (it seems to be available for Ubuntu and Debian).

It may be that I simply have an environment variable defined incorrectly, maybe I need to choose another backend for matplotlib, or need to abandon the pyplot module, what do you think?