471,624 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

Python/Tk not working in Linux

I am using Fedora Core 3 Linux and I have a problem with Tk in Python.
Whenever I try to run a tk script, I get the error...

---------------
Traceback (most recent call last):
File "Tk.py", line 1, in ?
from Tkinter import *
File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ?
import _tkinter # If this fails your Python may not be configured for
Tk
ImportError: No module named _tkinter
---------------

I get this error with even the most basic Python/Tk scripts like

---------------
from Tkinter import *

class Application(Frame):
def createWidgets(self):
self.lab = Label(text="Hello World")
self.lab.pack()

def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()

app = Application()
app.mainloop()
------------------

However python script that does not used Tk works fine.

I have tried to solve this problem by reinstalling Python from source -
but still no luck. Ruby also fails this way in my system - ruby works -
but not Ruby with Tk. However Perl/Tk and Tcl/Tk works fine.

Any suggestions?

--
Binny V A
http://www.bin-co.com/perl/perl_tk_tutorial/ - Perl/Tk
http://www.bin-co.com/tcl/tutorial/ - Tcl/Tk

Aug 12 '06 #1
4 3990
In <11**********************@m79g2000cwm.googlegroups .com>, BinnyVA wrote:
I am using Fedora Core 3 Linux and I have a problem with Tk in Python.
Whenever I try to run a tk script, I get the error...

---------------
Traceback (most recent call last):
File "Tk.py", line 1, in ?
from Tkinter import *
File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ?
import _tkinter # If this fails your Python may not be configured for
Tk
ImportError: No module named _tkinter
---------------
The `_tkinter` module is the binary "bridge" to the Tk system. If it's
not found it's most likely that the relevant header files of tcl/tk where
not installed before compiling Python or there was a problem while
compiling this extension.

This seems to be your self compiled Python. Are you sure you got the same
error when using the version from your distribution? I would suspect you
get an `ImportError` on `Tkinter` there. Some distributions move the
`Tkinter` stuff into an own package. Search for a package called
`python-tk` or `python-tkinter` or similar.

Ciao,
Marc 'BlackJack' Rintsch
Aug 12 '06 #2
In article <pa****************************@gmx.net>,
Marc 'BlackJack' Rintsch <bj****@gmx.netwrote:
>In <11**********************@m79g2000cwm.googlegroups .com>, BinnyVA wrote:
>I am using Fedora Core 3 Linux and I have a problem with Tk in Python.
Whenever I try to run a tk script, I get the error...

---------------
Traceback (most recent call last):
File "Tk.py", line 1, in ?
from Tkinter import *
File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ?
import _tkinter # If this fails your Python may not be configured for
Tk
ImportError: No module named _tkinter
---------------

The `_tkinter` module is the binary "bridge" to the Tk system. If it's
not found it's most likely that the relevant header files of tcl/tk where
not installed before compiling Python or there was a problem while
compiling this extension.

This seems to be your self compiled Python. Are you sure you got the same
error when using the version from your distribution? I would suspect you
get an `ImportError` on `Tkinter` there. Some distributions move the
`Tkinter` stuff into an own package. Search for a package called
`python-tk` or `python-tkinter` or similar.
Aug 12 '06 #3
Some distributions move the
`Tkinter` stuff into an own package. Search for a package called
`python-tk` or `python-tkinter` or similar.
I could use a 'python-tk' package - but the problem is the latest
version of python may not be available.

I am going to download Tcl/Tk and install it. Then I would try to
install Python once again. If that works, great. If not I will install
a full 'python-tk' package. Maybe
'ActivePython'(http://www.activestate.com/Products/...d=ActivePython)
like Cameron Laird have suggested.

--
Binny V A
http://www.bin-co.com/ - Bin-Co

Aug 14 '06 #4
In <11**********************@m79g2000cwm.googlegroups .com>, BinnyVA wrote:
>Some distributions move the `Tkinter` stuff into an own package.
Search for a package called `python-tk` or `python-tkinter` or similar.

I could use a 'python-tk' package - but the problem is the latest
version of python may not be available.
That's always the problem with packaged software. But you gain fast and
easy installation via the package system.
I am going to download Tcl/Tk and install it. Then I would try to
install Python once again.
Just install the necessary development packages for your installed Tcl/Tk
and compile the Python sources. Unless you really want to compile
everything yourself.

Ciao,
Marc 'BlackJack' Rintsch
Aug 14 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

65 posts views Thread by Anthony_Barker | last post: by
34 posts views Thread by Maboroshi | last post: by
7 posts views Thread by Edward Diener | last post: by
10 posts views Thread by callmebill | last post: by
25 posts views Thread by redefined.horizons | last post: by
1 post views Thread by Vyacheslav Sotnikov | last post: by
1 post views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.