LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-26-2004, 03:19 PM   #1
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Rep: Reputation: 30
Building Python with Tkinter support


I've got python installed on my RH9 machine, and I installed Tkinter and all of it's dependancies. When I run 'import tkinter' from the python shell, it says that the module cannot be found. I have read many places that this means I have to configure python to use tkinter, but I cannot find anything that tells me how to do it. Have any of you gotten this working? If so, how did you do it?

Thank you
 
Old 01-27-2004, 12:44 AM   #2
kolargol
LQ Newbie
 
Registered: Jan 2003
Posts: 18

Rep: Reputation: 0
have you tried "import Tkinter" with an uppercase T as first letter.
 
Old 01-27-2004, 07:38 AM   #3
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
That also does not work, I get the same error message with "No module named _tkinter"
 
Old 01-27-2004, 07:55 AM   #4
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Sounds like you didn't install Tkinter properly then. Care to describe how you installed it?
 
Old 01-27-2004, 08:11 AM   #5
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
I did it all from RPMs, and I made sure to install everything it required. Should I try to remove those and do it from source?
 
Old 01-27-2004, 06:33 PM   #6
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
What RPMs did you install? Where did you get them? What versions of each did you install? Are you sure they are successfully installed? etc.
 
Old 01-27-2004, 07:05 PM   #7
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
I did a rpm search at rpm.pbone.net for Tkinter, downloaded and installed tcl-8.3.1-53.i386.rpm and tk-8.3.3-4cl.i386.rpm. Also says I have tkinter-2.2.3-5.i386.rpm installed. I just checked the package section of my logs, and thats what I found
 
Old 01-28-2004, 07:52 AM   #8
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
There might be some sort of python-tk or python-tkinter package you have to install, as I'm not sure what is in the tkinter rpm. Also, does your python version match up with the tkinter version?
 
Old 01-28-2004, 09:05 AM   #9
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
My python is the newest one, I just got it and compiled it off of python.org. Version 2.3.3. My tkinter is 2.2.3, is that the problem then?
 
Old 01-28-2004, 09:53 AM   #10
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
If you got it and compiled it off of python.org, I think it includes Tkinter unless you tell it not to compile that .... but I haven't compiled Python in a looong time so I can't be sure.

To answer your question, though, yes if your version of Tkinter and your version of Python don't match up, then they won't work together (in all likelihood).
 
Old 01-28-2004, 10:14 AM   #11
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
Well.. I installed it, and it wasnt there. That was the original reason I started this thread, because I figured I hadnt specified to install it. What I am going to try to do is just remove all copies of python and tkinter and start over again. Should I install Python first, and then tkinter, or vice versa?
 
Old 01-28-2004, 04:38 PM   #12
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Well, like I said, if you are compiling Python from source from python.org, I think that it comes with Tkinter. You might have to specify some special build instructions to build it, so I'd check the docs that come with it. I've not compiled Python in a long time and I never worried about having Tkinter support when I did, so ... I'm not anywhere close to an expert on building Python or Tkinter.
 
Old 01-28-2004, 05:58 PM   #13
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
The docs only say to edit /modules/setup for tkinter support, but all that it says there is that tkinter is automatically enabled, and to 'edit the line below' if I want to change the directory. :s

Makes no sense at all, but it couldnt hurt to try reinstalling. I have Qt installed and working, is that a decent substitute?
 
Old 01-30-2004, 10:20 AM   #14
LinuxBlackBox
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Slackware 9
Posts: 243

Original Poster
Rep: Reputation: 30
I removed tkinter, and reinstalled it using apt-get, then I rebuit python. same error though. I dont suppose there is a way to manually copy the Tkinter files to the directory they need to be in, is there?
 
Old 02-15-2007, 10:10 AM   #15
jayjwa
Member
 
Registered: Jul 2003
Location: NY
Distribution: None (src & compile)
Posts: 253

Rep: Reputation: 36
The TCL Tickler

Since we're snowed in here in the North east US, I took the time to get to the bottom of this. All this time I thought I had a working _tkinter, until I tried to run fetchmailconf (ironically, I can hand-write its config files..., still, a bad milter-regex rule ate all 35 of my emails anyway so it didn't do much good, beyond what I figured out here.) Out of curiousity, I wonder just how many people have had this problem. It seems Python installs Tkinter.py anyway, even if Tk support as a whole doesn't work. Searching for "_tkinter " turns up a slew of posts, none that I saw with a solid answer. The file that matters, assuming you compiled python modules dynamically, is _tkinter.so:

Code:
 ldd /usr/lib/python2.5/lib-dynload/_tkinter.so

        linux-gate.so.1 =>  (0xb7f30000)
        /lib/libsafe.so.2 (0xb7f1e000)
        libtix.so => /usr/lib/libtix.so (0xb7ed0000)
        libtk8.5.so => /usr/lib/libtk8.5.so (0xb7df3000)
        libtcl8.5.so => /usr/lib/libtcl8.5.so (0xb7d10000)
        libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0xb7c43000)
        libpthread.so.0 => /lib/libpthread.so.0 (0xb7c2c000)
        libc.so.6 => /lib/libc.so.6 (0xb7ae9000)
        libdl.so.2 => /lib/libdl.so.2 (0xb7ae5000)
        libXss.so.1 => /usr/X11R6/lib/libXss.so.1 (0xb7ae2000)
        libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0xb7ad3000)
        libXft.so.2 => /usr/X11R6/lib/libXft.so.2 (0xb7ac1000)
        libfreetype.so.6 => /usr/local/lib/libfreetype.so.6 (0xb7a5a000)
        libfontconfig.so.1 => /usr/local/lib/libfontconfig.so.1 (0xb7a30000)
        libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0xb7a27000)
        libm.so.6 => /lib/libm.so.6 (0xb7a00000)
        /lib/ld-linux.so.2 (0x80000000)
        libexpat.so.0 => /usr/X11R6/lib/libexpat.so.0 (0xb79e2000)
        libz.so.1 => /usr/lib/libz.so.1 (0xb79cf000)
        libexpat.so.1 => /usr/lib/libexpat.so.1 (0xb79af000)
As you can see, it's quite the shlib beast. If you have working tkinter.so support, you should see this instead of an error message:

Code:
 python

Python 2.5 (r25:51908, Feb 14 2007, 15:43:17)
[GCC 4.1.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _tkinter
>>>
Most of the trouble seems to be not in Python itself, but in getting TCL/Tk/Tix to install, which is no small feat considering what one must do. The versions I used to preform this miracle are as follows, all off their (Sourceforge) project pages, and Python of its site page:
  • tcl-8.5a5
  • tk-8.5a5
  • thread-2.6.5
  • tix-8.4.0
  • Python-2.5

They are all current as of this writing. Likely you already have some version of these. My personal recommendation if you're going to do a full rebuild, is whack all of it with exception of the shared libs. Those move and tuck away someplace safe, in case something un-rebuildable is linking against them. If it is, simply copy them back and re-run ldconfig to update the ld.so.cache.
  1. Clean up the old version of those programs, including manpages, and docs.
  2. Unpack Tcl, Tk, and its Thread add-on. Each of these must be built twice: once non-shared and once shared. See the build scripts.
  3. TCL and Tk in the past did not install their headers properly. Apps in the past wanted the "private headers", which the install skipped. We use /usr/include/tcl for all these due to namespace clashes. See the build scripts for how to force their install. WIth Tix, you must manually find and copy them.
  4. Apply the two patches to fix up b0rked headers: tcl-8.5a5-hold-the-MODULE_SCOPE-kthx.patch.gz tix-8.4.0-ERR_IN_PROGRESS-is-nomore.patch.gz. I'm no C programmer, these are probably not the best ways to fix these, but it works.
  5. Clean up the TCL/Tk install. Both install tclConfig.sh/tkConfig.sh scripts in /usr/lib. These insist on referencing the build directory, which is about to rm -rf'ed. Remove all references to those paths by setting empty variables. Add -I/usr/include/tcl to the CFLAGS so the headers can be found later. Unversion the libraries: I find it highly annoying to have to link against -ltcl8.5a5. Easier is -ltcl. See the build scripts again for examples for both the .so libs and .a libs.
  6. Build Tix. See the tix build script for all the stuff that needs to be done. There is alot of minor fixes. Don't forget to lower-case the paths and lib names in unix tradition. Headers need to found in the source tarball and copied to /usr/include/tcl.
  7. Tixwish is MIA. Maybe it fell out of bag on the way home? Don't forget to un-version tclsh and wish. I hate typing "tclsh8.5.a.5.blah.blah.etc.and.so.on" instead of "tclsh"! Probably you will, too.
  8. Re-install python to link against the shiney-new TCL/Tk/Tix stuff. I've included the Modules/Setup file that shows what to select to get a working tkinter. Make sure you updated the shared libs ld.so.cache before python building.
  9. You can use Idle now as well. Marvel at the beautiful fetchmailconf program.

The magic shar: I've tried to upload this shar no less than 20 times, using three different ways, uuencoded, base64 encoded, and plain. 100% of the time it snaps my dial-up connection when I try to send it. Bonus points for figuring out why.

x100


OK then, let Googlebot chase this:
tftp://atr2.ath.cx/tcl-tk-tix-tickler.shar

Try again in awhile if the link is down, my ISP likes to disconnect me randomly.

You can probably use "sh" for the scripts if you don't have "zsh", but I know everyone has zsh because it's the best shell around

The scripts are meant to execute in the top level of the archive they are building. Actually, it's best you use the scripts as guide for what to type, and type in each command yourself and wait for it to run, rather than letting them fly on auto-pilot. They were made quickly as I worked thru this, so they are far from fault-tolerant or forgiving for multiple system layouts.

After this, when you want to build with tcl/tk/tix just do something like: gcc -o prog -I/usr/include/tcl tclprog.c -ltcl (or -ltk or -ltix, whichever the case may be).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tkinter integration to python 2.3.4 gaddargarson Programming 1 03-09-2005 04:58 AM
Python / Tkinter : 2 quick questions infidel Programming 0 12-31-2004 04:19 PM
Python and Tkinter 1337 Twinkie Fedora 2 08-03-2004 11:35 AM
Python: Tkinter. Chu Programming 0 11-10-2003 01:56 AM
Python and Tkinter Error Gerardoj Programming 1 11-08-2003 09:52 PM


All times are GMT -5. The time now is 11:17 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration