ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 16 Aug 2011 18:07:38 +0200sage-python, import matplotlib: no module named _tkagghttps://ask.sagemath.org/question/8197/sage-python-import-matplotlib-no-module-named-_tkagg/**EDIT 2: Below is the description of a problem and a subsequent edit, where I thought I had the solution. In fact, what I did was move the problem from one place to another... I am no longer receiving the error *No module named _tkagg* and I am getting a plot window, but after opening a tk window I get a stack trace that reads:**
Exception in Tkinter callback
Traceback (most recent call last):
File "/opt/sage/local/lib/python2.6/lib-tk/Tkinter.py", line 1410, in __call__
return self.func(*args)
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_tkagg.py", line 245, in resize
self.show()
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_tkagg.py", line 249, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/opt/sage/local/lib/python2.6/site-packages/matplotlib/backends/tkagg.py",
line 18, in blit
_tkagg.tkinit(id(tk), 0)
AttributeError: 'module' object has no attribute 'tkinit'
**along with no actual plot on the tk window. This issue remains unresolved.**
I am using Sage's python and trying to import matplotlib.pyplot in order to generate some visual output (to the screen for now, to a file at some point). I understand the backend I should use is TkAgg for this, and I have that set in my matplotlibrc file.
When running a short script pleasePlot.py:
# pleasePlot.py
import matplotlib.pyplot as plt
def main():
x = [0,1,2,3,4,5]
y = [1,6,4,4,2,7]
plt.plot(x,y)
plt.show()
main()
as
bash$ python pleasePlot.py
I am greeted with absolutely no output. When examining this closer, by running a sage-python (python2.6.4.p10) shell I get the following:
>>>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
I have tried
sage -f python-2.6.4.p10
sage -f matplotlib-1.0.1
but this does not magically fix the problem. As well, Google seems to not be much help. What do you think?
**EDIT 1:** FIXED! I am able to get a plot window from either the sage-python prompt -or- by running this 'program' from the bash shell. What I did was to track down the _tkagg call (by reading the stack trace more carefully) coming from the file
/opt/sage/local/lib/python2.6/site-packages/matplotlib/backends/tkagg.py
the file starts out as:
import _tkagg
yada yada yada
so I went searching around for _tkagg, which doesn't exist. What *does* exist is the module backend_tkagg.py, so I changed the import statement above to
import backend_tkagg as _tkagg
and the sun came out. Tue, 28 Jun 2011 16:41:40 +0200https://ask.sagemath.org/question/8197/sage-python-import-matplotlib-no-module-named-_tkagg/Answer by Alex for <div class="snippet"><p><strong>EDIT 2: Below is the description of a problem and a subsequent edit, where I thought I had the solution. In fact, what I did was move the problem from one place to another... I am no longer receiving the error <em>No module named _tkagg</em> and I am getting a plot window, but after opening a tk window I get a stack trace that reads:</strong></p>
<pre><code>Exception in Tkinter callback
Traceback (most recent call last):
File "/opt/sage/local/lib/python2.6/lib-tk/Tkinter.py", line 1410, in __call__
return self.func(*args)
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_tkagg.py", line 245, in resize
self.show()
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_tkagg.py", line 249, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/opt/sage/local/lib/python2.6/site-packages/matplotlib/backends/tkagg.py",
line 18, in blit
_tkagg.tkinit(id(tk), 0)
AttributeError: 'module' object has no attribute 'tkinit'
</code></pre>
<p><strong>along with no actual plot on the tk window. This issue remains unresolved.</strong></p>
<p>I am using Sage's python and trying to import matplotlib.pyplot in order to generate some visual output (to the screen for now, to a file at some point). I understand the backend I should use is TkAgg for this, and I have that set in my matplotlibrc file. </p>
<p>When running a short script pleasePlot.py:</p>
<pre><code># pleasePlot.py
import matplotlib.pyplot as plt
def main():
x = [0,1,2,3,4,5]
y = [1,6,4,4,2,7]
plt.plot(x,y)
plt.show()
main()
</code></pre>
<p>as </p>
<pre><code>bash$ python pleasePlot.py
</code></pre>
<p>I am greeted with absolutely no output. When examining this closer, by running a sage-python (python2.6.4.p10) shell I get the following:</p>
<pre><code>>>>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>I have tried </p>
<pre><code>sage -f python-2.6.4.p10
sage -f matplotlib-1.0.1
</code></pre>
<p>but this does not magically fix the problem. As well, Google seems to not be much help. What do you think?</p>
<p><strong>EDIT 1:</strong> FIXED! I am able to get a plot window from either the sage-python prompt -or- by running this 'program' from the bash shell. What I did was to track down the _tkagg call (by reading the stack trace more carefully) coming from the file </p>
<pre><code>/opt/sage/local/lib/python2.6/site-packages/matplotlib/backends/tkagg.py
</code></pre>
<p>the file starts out as:</p>
<pre><code>import _tkagg
yada yada yada
</code></pre>
<p>so I went searching around ...<span class="expander"> <a>(more)</a></span></p></div> https://ask.sagemath.org/question/8197/sage-python-import-matplotlib-no-module-named-_tkagg/?answer=12582#post-id-12582Hi,
I have got the same problem after compiling SAGE on my notebook. I searched in the web and I found that the file _tkagg.so is missed in the folder /sage-4.7/local/lib/python2.6/site-packages/matplotlib/backends (if I understood well, it was a bug of matplotlib).
You can find this file at http://rpmfind.net/linux/rpm2html/search.php?query=_tkagg.so
I use Ubuntu 11.04, there is no file specific for it, so I decided to try with the file for Fedora 14 for i386. I copied it in the folder above and it looks to work well (I tried a couple of graphs).
Tue, 16 Aug 2011 18:07:38 +0200https://ask.sagemath.org/question/8197/sage-python-import-matplotlib-no-module-named-_tkagg/?answer=12582#post-id-12582Answer by Jason Grout for <div class="snippet"><p><strong>EDIT 2: Below is the description of a problem and a subsequent edit, where I thought I had the solution. In fact, what I did was move the problem from one place to another... I am no longer receiving the error <em>No module named _tkagg</em> and I am getting a plot window, but after opening a tk window I get a stack trace that reads:</strong></p>
<pre><code>Exception in Tkinter callback
Traceback (most recent call last):
File "/opt/sage/local/lib/python2.6/lib-tk/Tkinter.py", line 1410, in __call__
return self.func(*args)
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_tkagg.py", line 245, in resize
self.show()
File "/opt/sage/local/lib/python2.6/site-
packages/matplotlib/backends/backend_tkagg.py", line 249, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/opt/sage/local/lib/python2.6/site-packages/matplotlib/backends/tkagg.py",
line 18, in blit
_tkagg.tkinit(id(tk), 0)
AttributeError: 'module' object has no attribute 'tkinit'
</code></pre>
<p><strong>along with no actual plot on the tk window. This issue remains unresolved.</strong></p>
<p>I am using Sage's python and trying to import matplotlib.pyplot in order to generate some visual output (to the screen for now, to a file at some point). I understand the backend I should use is TkAgg for this, and I have that set in my matplotlibrc file. </p>
<p>When running a short script pleasePlot.py:</p>
<pre><code># pleasePlot.py
import matplotlib.pyplot as plt
def main():
x = [0,1,2,3,4,5]
y = [1,6,4,4,2,7]
plt.plot(x,y)
plt.show()
main()
</code></pre>
<p>as </p>
<pre><code>bash$ python pleasePlot.py
</code></pre>
<p>I am greeted with absolutely no output. When examining this closer, by running a sage-python (python2.6.4.p10) shell I get the following:</p>
<pre><code>>>>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>I have tried </p>
<pre><code>sage -f python-2.6.4.p10
sage -f matplotlib-1.0.1
</code></pre>
<p>but this does not magically fix the problem. As well, Google seems to not be much help. What do you think?</p>
<p><strong>EDIT 1:</strong> FIXED! I am able to get a plot window from either the sage-python prompt -or- by running this 'program' from the bash shell. What I did was to track down the _tkagg call (by reading the stack trace more carefully) coming from the file </p>
<pre><code>/opt/sage/local/lib/python2.6/site-packages/matplotlib/backends/tkagg.py
</code></pre>
<p>the file starts out as:</p>
<pre><code>import _tkagg
yada yada yada
</code></pre>
<p>so I went searching around ...<span class="expander"> <a>(more)</a></span></p></div> https://ask.sagemath.org/question/8197/sage-python-import-matplotlib-no-module-named-_tkagg/?answer=12492#post-id-12492For 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 20:39:17 +0200https://ask.sagemath.org/question/8197/sage-python-import-matplotlib-no-module-named-_tkagg/?answer=12492#post-id-12492Comment by Jason Grout for <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/8197/sage-python-import-matplotlib-no-module-named-_tkagg/?comment=21507#post-id-21507Ah, it looks like you moved on from my answer. Can you post your solution as an "answer" so that people know the question is resolved?Mon, 04 Jul 2011 20:40:45 +0200https://ask.sagemath.org/question/8197/sage-python-import-matplotlib-no-module-named-_tkagg/?comment=21507#post-id-21507