sage-python, import matplotlib: no module named _tkagg

i like this post (click again to cancel)
1
i dont like this post (click again to cancel)

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.

asked Jun 28 '11

tdstephens3 gravatar image tdstephens3
17 2 2 7

updated Jun 28 '11

2 Answers:

i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel) tdstephens3 has selected this answer as correct

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.

link

posted Jul 04 '11

Jason Grout gravatar image Jason Grout
3315 7 29 74

updated Jul 04 '11

Ah, 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? Jason Grout (Jul 04 '11)
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Hi,

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).

link

posted Aug 16 '11

Alex gravatar image Alex
1

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
Login/Signup to Post

Question tools

Tags:

Stats:

Asked: Jun 28 '11

Seen: 1,990 times

Last updated: Aug 16 '11

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.