Python/Tk not working in Linux

Discussion in 'Python' started by BinnyVA, Aug 12, 2006.

  1. BinnyVA

    BinnyVA Guest

    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
     
    BinnyVA, Aug 12, 2006
    #1
    1. Advertisements

  2. In <>, 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
     
    Marc 'BlackJack' Rintsch, Aug 12, 2006
    #2
    1. Advertisements

  3. In article <>,
    Marc 'BlackJack' Rintsch <> wrote:
    >In <>, 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.

    .
    .
    .
    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.
     
    Cameron Laird, Aug 12, 2006
    #3
  4. BinnyVA

    BinnyVA Guest

    > 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.

    --
    Binny V A
    http://www.bin-co.com/ - Bin-Co
     
    BinnyVA, Aug 14, 2006
    #4
  5. In <>, 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
     
    Marc 'BlackJack' Rintsch, Aug 14, 2006
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    417
  2. Matthias Sommer
    Replies:
    0
    Views:
    422
    Matthias Sommer
    May 28, 2008
  3. Chris Ortner
    Replies:
    0
    Views:
    362
    Chris Ortner
    Jun 23, 2008
  4. Knut Krueger
    Replies:
    11
    Views:
    1,055
    Jeff Thies
    May 3, 2011
  5. Zac Elston
    Replies:
    0
    Views:
    182
    Zac Elston
    Feb 21, 2007
  6. Just Another Victim of the Ambient Morality

    Mechanize for Ruby on Linux not working...

    Just Another Victim of the Ambient Morality, Sep 13, 2008, in forum: Ruby
    Replies:
    3
    Views:
    191
    Cameron McBride
    Sep 14, 2008
  7. Martin Mohr

    Term::ReadKey not working on one linux box

    Martin Mohr, Mar 21, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    206
    Martin Mohr
    Mar 26, 2006
  8. ian douglas
    Replies:
    5
    Views:
    294
    88888 Dihedral
    Mar 5, 2013
Loading...