Python/Tk not working in Linux

B

BinnyVA

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?
 
M

Marc 'BlackJack' Rintsch

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
 
C

Cameron Laird

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.
.
.
.
ALSO, Fedora has been a particular problem at times--I haven't
researched where FC3 is in this regard--because it distributed
non-standard Tk-s that yielded weird breakages. If you're
caught in one of these conflicts, you might not be able to
generate from sources correctly because development headers are
inconsistent with sources.

So: you can generate all of Python and Tk from sources you
believe are clean; or you can take advantage of full binaries,
such as ActivePython, that someone else has made.
 
B

BinnyVA

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/Download/Download.plex?id=ActivePython)
like Cameron Laird have suggested.
 
M

Marc 'BlackJack' Rintsch

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top