Ask Your Question
1

sage-python, import matplotlib: no module named _tkagg

asked 2011-06-28 16:41:40 +0200

tdstephens3 gravatar image

updated 2011-06-28 17:44:09 +0200

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-07-04 20:39:17 +0200

Jason Grout gravatar image

updated 2011-07-04 20:41:50 +0200

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.

edit flag offensive delete link more

Comments

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 gravatar imageJason Grout ( 2011-07-04 20:40:45 +0200 )edit
0

answered 2011-08-16 18:07:38 +0200

Alex gravatar image

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

edit flag offensive delete link more

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: 2011-06-28 16:41:40 +0200

Seen: 5,575 times

Last updated: Aug 16 '11