First time here? Check out the FAQ!

Ask Your Question
0

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

asked 13 years ago

tdstephens3 gravatar image

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 13 years ago

Jason Grout gravatar image

Sage is looking for those bindings installed in Sage's copy of python. You can install things in Sage's copy of python by doing "sage -sh" and then whatever you normally would do to install the python bindings.

For Sage's matplotlib, the graphical guis are also turned off by default. Define the environment variable:

export SAGE_MATPLOTLIB_GUI=yes

and then reinstall Sage's matplotlib:

sage -i matplotlib

to compile support for other backends in Sage.

Preview: (hide)
link

Comments

Shouldn't it be sage -f matplotlib ?

Jesustc gravatar imageJesustc ( 12 years ago )

Still, it does not work for me: I get the same error when importing :(

Jesustc gravatar imageJesustc ( 12 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 2,739 times

Last updated: Jul 04 '11