Configuring Python for Tk on Mac

M

Martyn Quick

On my desk here at work I have a Mac G4 running Mac OS X v10.2.8.

When I go into a terminal and type "python" up comes a nice python
interface and all seems great. However when I type "import Tkinter"
I'm greeted by the following error.
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 35, in ?
import _tkinter # If this fails your Python may not be configured
for Tk
ImportError: No module named _tkinter

So I guess something about this implementation is not appropriately
configured. I'm guessing this is the default behaviour since I don't
think anyone did anything special about python when they set up my
machine.

What do I do to set it up so I can use Tkinter?

Thanks... and sorry if this is an FAQ... but I couldn't find the info
easily.

Yours,
Martyn
 
C

Craig Ringer

On my desk here at work I have a Mac G4 running Mac OS X v10.2.8.

When I go into a terminal and type "python" up comes a nice python
interface and all seems great. However when I type "import Tkinter"
I'm greeted by the following error.

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

So I guess something about this implementation is not appropriately
configured.

In general, that error means that Python can't find the C extension
module used to provide the low-level interface for Tkinter. It's not
installed, can't be found (library path or python path issues), can't be
opened (permissions), etc.

Note the comment in the error message to that effect.

I've just checked the OSX 10.3 machine here, and it fails to import
tkinter there too. I'd say Apple just don't build Python with Tk
support.
What do I do to set it up so I can use Tkinter?

Try Google - this seems to be a moderately FAQ for MacOS/X.
 
J

Jim Sizelove

Martyn said:
On my desk here at work I have a Mac G4 running Mac OS X v10.2.8.

When I go into a terminal and type "python" up comes a nice python
interface and all seems great. However when I type "import Tkinter"
I'm greeted by the following error.



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

So I guess something about this implementation is not appropriately
configured. I'm guessing this is the default behaviour since I don't
think anyone did anything special about python when they set up my
machine.

What do I do to set it up so I can use Tkinter?

Thanks... and sorry if this is an FAQ... but I couldn't find the info
easily.

Yours,
Martyn


You probably need to install Tcl/Tk Aqua:
http://tcltkaqua.sourceforge.net

After downloading and installing on my Mac running OS X v 10.2, I am
able to open IDLE and other Tk apps.

HTH,

Jim Sizelove
 
A

Alex Martelli

Craig Ringer said:
I've just checked the OSX 10.3 machine here, and it fails to import
tkinter there too. I'd say Apple just don't build Python with Tk
support.

No idea about any 10.2, sorry, but on 10.3 that's not the problem: Tk
support is there alright, it's Tcl/Tk which _isn't_. Get MacPython, its
PackageManager will explain where to get Tcl/Tk Aqua from, as a prereq
for Tkinter and IDLE!


Alex
 
R

Russell E. Owen

On my desk here at work I have a Mac G4 running Mac OS X v10.2.8.

When I go into a terminal and type "python" up comes a nice python
interface and all seems great. However when I type "import Tkinter"
I'm greeted by the following error....

Assuming you are running MacPython from
<http://homepages.cwi.nl/~jack/macpython/macpython-osx.html>...

Install Aqua Tcl/Tk as another poster suggested.

Run Applications/MacPython.../Package Manager and install Tkinter.

Or if your MacPython is out of date, you may just want to download and
install the current version. If Tcl/Tk is already installed then I think
it will install Tkinter automatically (but if not, use Package Manager).

If you are running some other python, please tell us more about it. (If
it's fink python, install the version that includes Tkinter support, but
this runs on X11 instead of Aqua).

-- Russell
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top