ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 07 Mar 2013 04:56:22 -0600sage-python, matplotlib.pyplot: backends tk and pygtk not recognizedhttps://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/I am trying to solve the problem I was having in [this question](http://ask.sagemath.org/question/626/sage-python-import-matplotlib-no-module-named) - 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](http://www.sagemath.org/doc/faq/faq-usage.html#how-to-get-sage-s-python-to-recognize-my-system-s-tcl-tk-install) 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?
Thu, 30 Jun 2011 06:57:55 -0500https://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/Answer by Jason Grout for <p>I am trying to solve the problem I was having in <a href="http://ask.sagemath.org/question/626/sage-python-import-matplotlib-no-module-named">this question</a> - but since I did a clean sage install since then I figured I would start a new question. </p>
<p>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). </p>
<p><strong>The problem is this:</strong> </p>
<p>From the bash prompt with matplotlibrc backend specified as GTKAgg:</p>
<pre><code>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.
</code></pre>
<p>From the bash prompt with matplotlibrc backend specified as TkAgg:</p>
<pre><code>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
</code></pre>
<p>Now, I am running Arch Linux and according to my package manager, pacman, I have</p>
<pre><code>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
</code></pre>
<p>I have looked <a href="http://www.sagemath.org/doc/faq/faq-usage.html#how-to-get-sage-s-python-to-recognize-my-system-s-tcl-tk-install">here</a> 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). </p>
<p>It may be that I simply have an <strong>environment variable</strong> defined incorrectly, maybe I need to choose another <strong>backend for matplotlib</strong>, or need to <strong>abandon the pyplot module</strong>, what do you think? </p>
https://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/?answer=12491#post-id-12491Sage 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.Mon, 04 Jul 2011 13:38:43 -0500https://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/?answer=12491#post-id-12491Comment by Jesustc for <p>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.</p>
<p>For Sage's matplotlib, the graphical guis are also turned off by default. Define the environment variable:</p>
<pre><code>export SAGE_MATPLOTLIB_GUI=yes
</code></pre>
<p>and then reinstall Sage's matplotlib:</p>
<pre><code>sage -i matplotlib
</code></pre>
<p>to compile support for other backends in Sage.</p>
https://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/?comment=18090#post-id-18090Shouldn't it be
sage -f matplotlib
?Thu, 07 Mar 2013 04:43:41 -0600https://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/?comment=18090#post-id-18090Comment by Jesustc for <p>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.</p>
<p>For Sage's matplotlib, the graphical guis are also turned off by default. Define the environment variable:</p>
<pre><code>export SAGE_MATPLOTLIB_GUI=yes
</code></pre>
<p>and then reinstall Sage's matplotlib:</p>
<pre><code>sage -i matplotlib
</code></pre>
<p>to compile support for other backends in Sage.</p>
https://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/?comment=18089#post-id-18089Still, it does not work for me: I get the same error when importing :(Thu, 07 Mar 2013 04:56:22 -0600https://ask.sagemath.org/question/8203/sage-python-matplotlibpyplot-backends-tk-and-pygtk-not-recognized/?comment=18089#post-id-18089