# Revision history [back]

### sage-python, import matplotlib: no module named _tkagg

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:

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? ### sage-python, import matplotlib: no module named _tkagg 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: 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

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.

### [SOLVED] sage-python, import matplotlib: no module named _tkagg

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:

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: 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. ### [SOLVED] 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 backend_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: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

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.

### 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
backend_tkagg.tkinit(id(tk), _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:

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

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