Tkinter module not found

S

Shuaib

Hey,

Even though I freshly installed Tcl and Tk, python still seem to have
problems accessing Tkinter module. Here is what says when I do "import
Tkinter"

==
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named Tkinter
==

Any ideas how to fix this problem? (Gentoo distribution)

Thanks.
 
J

John Salerno

Shuaib said:
Hey,

Even though I freshly installed Tcl and Tk, python still seem to have
problems accessing Tkinter module. Here is what says when I do "import
Tkinter"

==
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named Tkinter
==

Any ideas how to fix this problem? (Gentoo distribution)

Thanks.

The cause of this is usually that you are using a different version of
Python than the one you installed Tkinter into, but being a Linux newbie
I have yet to discover how to redirect the 'python' command to invoke
the newer version of Python.
 
T

Tim Chase

The cause of this is usually that you are using a different
version of Python than the one you installed Tkinter into, but
being a Linux newbie I have yet to discover how to redirect
the 'python' command to invoke the newer version of Python.


The OS looks for the first 'python' it finds in its path.

In Linux (or other *nix OSes), you can use

bash> which python

and it will reply with which python it's pointing to. You can
then change into that directory (usually "/usr/bin") and get back
a listing of various pythons. On my Debian linux distro at home,
I get something back that looks like

bash> which python
/usr/bin/python
bash> cd /usr/bin
bash> ls -lsF python* | grep -o "python.*"
python -> python2.3*
python2.3*
python2.4*

You *should* be able to just relink the "python" link to the new
version of python:

bash> ln -sf /usr/bin/python2.4 /usr/bin/python

I don't know if this will cause other problems down the line for
packages that expect the system default.

Alternatively, at least on my system, you can force your choice
by explicity running "python2.3" or "python2.4" instead of just
"python".

You can determine your path via

bash> echo $PATH

along which your shell will search for an executable.

Win32 has a similar executable search path

c:\> echo %PATH%

but doesn't have something as handy as the "which" command to do
the hunting for you.

HTH,

-tkc
 
J

John Salerno

Tim said:
The OS looks for the first 'python' it finds in its path.

In Linux (or other *nix OSes), you can use

bash> which python

A very helpful command to know! I'll have to wait til I get home to play
on Linux though. Then I can try these things you suggested.

I'm suddenly very bored here at work using Windows. :)
 
S

Shuaib

Hey again,

I am using the latest python available on my system (2.4). So I don't
think that's the problem.

Any more ideas? Do I need to install Tkinter as a seperate
module/package? As I said, I've already installed Tcl/Tk, though.

Thanks for your time.
 
J

John Salerno

Shuaib said:
Hey again,

I am using the latest python available on my system (2.4). So I don't
think that's the problem.

Any more ideas? Do I need to install Tkinter as a seperate
module/package? As I said, I've already installed Tcl/Tk, though.

Hmm, yes, I think tkinter is separate from Tk, so you might try doing a
search for it in your repositories and see if something comes up that
you don't have installed yet.
 
T

Thomas Heller

John said:
A very helpful command to know! I'll have to wait til I get home to play
on Linux though. Then I can try these things you suggested.

I'm suddenly very bored here at work using Windows. :)
Well, we have python, haven't we?


Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

c:\>which python
c:\util\python.EXE

c:\>which which
c:\util\which.PY

c:\>type \util\which.py
import os, string, sys
PATH = os.environ["PATH"]
PATHEXT = os.environ["PATHEXT"]

all = 0
if sys.argv[1] == "-a":
del sys.argv[1]
all = 1

arg = sys.argv[1]

base, ext = os.path.splitext (arg)
for path in string.split (PATH, ';'):
if not ext:
for extension in string.split(PATHEXT, ';'):
if os.path.isfile(path + '\\' + arg + extension):
print path + '\\' + arg + extension
if not all:
sys.exit (0)
else:
if os.path.isfile (path + '\\' + arg):
print path + '\\' + arg
if not all:
sys.exit (0)

c:\>


There may be better variants of which out there...

Thomas
 
D

Dan

Shuaib said:
Hey again,

I am using the latest python available on my system (2.4). So I don't
think that's the problem.

Any more ideas? Do I need to install Tkinter as a seperate
module/package? As I said, I've already installed Tcl/Tk, though.

This is a wild guess, but I just installed Python 2.5b3 from source to
play with it, and on the first attempt I didn't get Tkinter. Turns out
I was missing tcl.h and tk.h in /usr/include. On my system (Fedora), I
had to install tcl-devel and tk-devel to get those header files.

Since you mentioned Gentoo, which builds from source, maybe you have a
similar issue. Although you'd think there'd be some dependency checking
in your package system that would catch it. Like I said, this is just
a wild guess.

/Dan
 
S

Shuaib

Well, I finally solved my problem. I just had to reinstall python with
the USE flags of tcl and tk.

#USE="tcl tk" emerge python

And now I can use Tkinter

Thanks guys!
 
P

Philippe Martin

Shuaib said:
Hey,

Even though I freshly installed Tcl and Tk, python still seem to have
problems accessing Tkinter module. Here is what says when I do "import
Tkinter"

==
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named Tkinter
==

Any ideas how to fix this problem? (Gentoo distribution)

Thanks.
That happened once to me when I compiled python without tcl/tk installed
(prior to compiling)
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top