Python et Tkinter sous Kubuntu

Résolu
Hello,
J'ai un petit souci pour appeler Tkinter avec Python :
yoan@PRECISION:~/Desktop/python$ python
Python 2.4.3 (#1, Aug 23 2006, 11:43:00)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Tkinter import *
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  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
>>>

J'ai tenté un apt-get install --reinstall python mais ça n'a pas bougé.

Quelqu'un a-t-il une idée ?
Merci.
--
L'urgent est fait, l'impossible est en cours,
Pour les miracles, prévoir un délai ...
Configuration: Linux
Firefox 2.0.0.1

13 réponses

Résumé de la discussion

Problème rencontré: l'import de Tkinter échoue avec Python 2.4 sur Linux, affichant ImportError: No module nommé _tkinter et rendant Tkinter inaccessible. Plusieurs solutions proposées incluent l'installation du paquet python-tk et la vérification que la version Python utilisée est compatible avec Tk, ainsi que la correction de l'emplacement du binaire. Des témoignages indiquent qu'une coexistence de Python 2.4 et 2.5 peut bloquer Tkinter, et que pointer /usr/bin/python vers une version plus récente résout le problème. D'autres indiquent qu'après avoir choisi Python 2.5 ou supérieur et réinstaller python-tk, Tkinter s'initialise sans erreur dans les environnements modernes.

Bobot (l’IA à votre service)
  1. Modérateur
    ben tout ça :
    python -V
    mv /usr/local/bin/python /usr/local/bin/python.save
    ls -l $(which python)
    python -V
    et pour la 3e commande il m'a coupé le début parce que c'était trop long, puis même si je copiait ce que j'avais ça risquait d'être lourd sur la page :)

    et dès que j'ai refait :
    ls -l $(which python)
    python -V
    c'était bon.
    1. Modérateur
      Ah, d'accord.

      Bonne journée :-)
  2. Modérateur
    La série de commande est trop longue pour que je la copie

    Ben, vu à quel point t'es paresseux tu peux faire de Perl :-))
    Les trois grandes vertus du programmeur sont la paresse, l'impatience et l'orgueil. Reportez-vous au livre ``Programmation en Perl'' (le Camel Book) pour savoir pourquoi.

    Ok, mais tu as fait quoi pour obtenir
    yoan@PRECISION:~$ ls -l $(which python)
    lrwxrwxrwx 1 root root 18 2007-02-18 15:54 /usr/bin/python -> /usr/bin/python2.5 ?
    1. Modérateur
      La série de commande est trop longue pour que je la copie. Maintenant j'ai ça :
      yoan@PRECISION:~$ python -V
      Python 2.5
      yoan@PRECISION:~$ ls -l $(which python)
      lrwxrwxrwx 1 root root 18 2007-02-18 15:54 /usr/bin/python -> /usr/bin/python2.5
      yoan@PRECISION:~$ python
      Python 2.5 (r25:51908, Oct  6 2006, 15:22:41)
      [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu4)] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>>


      et Tk fonctionne :)
      Merci !
      1. Modérateur
        C'est pour ça que ton lien ne fonctionne pas correctement.
        Comment ça se fait que tu as un python en /usr/local/bin

        Tape et affiche (les 4 commandes, une après l'autre)
        python -V
        mv /usr/local/bin/python /usr/local/bin/python.save
        ls -l $(which python)
        python -V
        1. Modérateur
          Je sais pas bien ce que je fais mais je le fais :)
          ls -l $(which python)
          -rwxr-xr-x 2 root root 2966741 2006-08-23 11:44 /usr/local/bin/python
          
          1. Modérateur
            Affiche
            root@PRECISION:/usr/bin# echo $PATH
            1. Modérateur
              /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
              

              :-)
          2. Modérateur
            Salut,

            Chez moi ça marche avec 2.4
            lami20j@debian:~$ ls -l /usr/bin/python
            lrwxrwxrwx 1 root root 9 2003-08-11 09:52 /usr/bin/python -> python2.4
            lami20j@debian:~$ python
            Python 2.4.4 (#2, Jan 13 2007, 17:50:26)
            [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
            Type "help", "copyright", "credits" or "license" for more information.
            >>>

            Je ne sais pas si ça peut avoir une influence. Es-tu sous Sarge?

            Tu peux passer à Etch (pas besoin de tout réinstaller) - à toi de voir
            sed -i.orig 's/^/#/' /etc/apt/sources.list
            Mets ça dans /etc/apt/sources.list
            deb ftp://ftp.fr.debian.org/debian/ etch main non-free contrib
            deb-src ftp://ftp.fr.debian.org/debian/ etch main non-free contrib
            
            
            deb https://www.debian.org/security/ etch/updates main contrib non-free
            deb-src https://www.debian.org/security/ etch/updates main contrib non-free
            Ensuite tape
            apt-get update
            apt-get -u dist-upgrade


            Ton Sarge deviendra Etch :-))

            1. Contributeur
              Je crois que Yoan est sous Kubuntu,
              perso je suis moi aussi sous etch depuis fin 2006 :)
            2. Modérateur
              @raspouteSalut,

              Je crois que Yoan est sous Kubuntu,

              Oups,

              tu as raison :-))
          3. Contributeur
            as-tu essayé avec idle-python ?
            1. Modérateur
              erf, il ne démarre pas l'interface :
              ~$ idle python
              ** IDLE can't import Tkinter.  Your Python may not be configured for Tk. **
            2. Contributeur
              @Yoanah
              aurais-tu installé plusieurs versions de python par hasard ?
              j'avais le même genre de problème sous debian sarge, tkinter fonctionnait avec python 2.3, mais pas avec python 2.4.
            3. Modérateur
              @raspouteoui :)
              il y a python 2.4 et python 2.5
              Le problème c'est que si je veux virer python 2.4 il veut m'enlever tout ça aussi :

              Les paquets suivants seront ENLEVÉS :
                adept adept-batch adept-common adept-installer adept-manager adept-notifier
                adept-updater akregator alsa-utils amarok amarok-xine amor ark artsbuilder
                atlantik atlantikdesigner bicyclerepair blinken cervisia dcoprss digikam
                eyesapplet fifteenapplet filelight gimp-python gtk2-engines-gtk-qt gwenview
                hplip hwdb-client-common hwdb-client-kde juk k3b kaboodle kaddressbook
                kaddressbook-plugins kaffeine kaffeine-xine kalarm kalzium kamera kanagram
                kandy kappfinder karm kasteroids katapult kate kate-plugins katomic
                kaudiocreator kbackgammon kbattleship kblackbox kbounce kbruch kbstate
                kcalc kcharselect kcoloredit kcontrol kcron kdat kde-amusements kde-core
                kde-guidance kde-guidance-powermanager kde-style-lipstik kde-systemsettings
                kdeaccessibility kdeaddons kdeaddons-kfile-plugins kdeadmin
                kdeadmin-kfile-plugins kdeartwork kdeartwork-style kdeartwork-theme-window
                kdebase kdebase-bin kdebase-kio-plugins kdebluetooth kdeedu kdegames
                kdegraphics kdegraphics-kfile-plugins kdelibs kdelibs4c2a kdelirc
                kdemultimedia-kappfinder-data kdemultimedia-kfile-plugins
                kdemultimedia-kio-plugins kdenetwork kdenetwork-filesharing
                kdenetwork-kfile-plugins kdepasswd kdepim kdepim-kfile-plugins
                kdepim-kio-plugins kdepim-kresources kdepim-wizards kdeprint kdesdk-scripts
                kdesktop kdessh kdetoys kdeutils kdewebdev kdf kdict kdm kdnssd kdvi kedit
                keduca keep kenolaba kfax kfaxview kfilereplace kfind kfloppy kfouleggs
                kftpgrabber kgamma kget kghostview kgoldrunner kgpg khangman khelpcenter
                khexedit kicker kicker-applets kiconedit kig kimagemapeditor kio-apt
                kio-locate kipi-plugins kitchensync kiten kjots kjumpingcube klaptopdaemon
                klatin kleopatra klettres klickety klines klinkstatus klipper kmag
                kmahjongg kmail kmailcvt kmenuedit kmid kmilo kmines kmix kmoon kmousetool
                kmouth kmplayer-base kmplayer-konq-plugins kmplot kmrml knetwalk
                knetworkconf knewsticker knewsticker-scripts knode knotes kodo koffice-libs
                kolf kolourpaint kommander kompare konq-plugins konqueror
                konqueror-nsplugins konquest konsole konsolekalendar kontact konversation
                kooka kopete korganizer korn kpackage kpager kpat kpdf kpercentage
                kpersonalizer kpf kpilot kpoker kpovmodeler kppp krdc krec kregexpeditor
                kreversi krfb krita kruler ksame ksayit kscd kscreensaver
                kscreensaver-xsavers kshisen ksig ksim ksirc ksirtet ksmiletris ksmserver
                ksnake ksnapshot ksokoban kspaceduel ksplash ksplash-engine-moodin kstars
                ksvg ksync ksysguard ksystemlog ksysv ktalkd kteatime ktimer ktip ktnef
                ktorrent ktouch ktron kttsd ktuberling kturtle ktux
                kubuntu-default-settings kubuntu-desktop kubuntu-docs
                kubuntu-konqueror-shortcuts kuser kverbos kview kviewshell kvoctrain
                kwalletmanager kweather kwifimanager kwin kwin-style-crystal kwin4
                kwordquiz kworldclock kxsldbg language-selector-common language-selector-qt
                language-support-en launchpad-integration libarts1-mpeglib libarts1-xine
                libboost-python1.33.1 libcvsservice0 libk3b2 libk3b2-mp3 libkcal2b
                libkcddb1 libkdeedu3 libkdegames1 libkdepim1a libkexif1 libkgantt0 libkipi0
                libkiten1 libkleopatra1 libkmime2 libkonq4 libkpimexchange1
                libkpimidentities1 libkscan1 libksieve0 libktnef1 libpythonize0 librss1
                libskim0 lilo-config lisa lsb-release lskat mpeglib networkstatus noatun
                noatun-plugins openoffice.org openoffice.org-help-en-us openoffice.org-kde
                openoffice.org-writer pykdeextensions python python-adns python-apt
                python-cairo python-cddb python-central python-clientcookie python-crypto
                python-dbus python-egenix-mxproxy python-egenix-mxstack
                python-egenix-mxtexttools python-egenix-mxtools python-elementtree
                python-epydoc python-eunuchs python-examples python-gadfly python-gd
                python-gdbm python-genetic python-geoip python-glade2 python-gnupginterface
                python-gobject python-gtk2 python-htmlgen python-htmltmpl python-id3lib
                python-imaging python-imaging-sane python-jabber python-kde3
                python-kjbuckets python-ldap python-libxml2 python-mysqldb python-netcdf
                python-newt python-numeric python-numeric-ext python-numeric-tutorial
                python-pam python-parted python-pexpect python-pgsql python-pisock
                python-pqueue python-pyao python-pylibacl python-pyogg python-pyopenssl
                python-pyvorbis python-pyxattr python-qt3 python-qt4 python-reportlab
                python-scientific python-simpletal python-sip4 python-soappy python-sqlite
                python-stats python-support python-syck python-tk python-unit python-uno
                python-xdg python-xlib python-xml python-xmpp python2.4 python2.4-adns
                python2.4-clientcookie python2.4-crypto python2.4-dev python2.4-dictclient
                python2.4-egenix-mxdatetime python2.4-egenix-mxproxy
                python2.4-egenix-mxstack python2.4-egenix-mxtexttools
                python2.4-egenix-mxtools python2.4-epydoc python2.4-eunuchs
                python2.4-examples python2.4-gadfly python2.4-gd python2.4-geoip
                python2.4-htmlgen python2.4-htmltmpl python2.4-id3lib python2.4-imaging
                python2.4-imaging-sane python2.4-jabber python2.4-kjbuckets python2.4-ldap
                python2.4-librdf python2.4-mysqldb python2.4-pam python2.4-pexpect
                python2.4-pgsql python2.4-pycurl python2.4-pylibacl python2.4-pyopenssl
                python2.4-pyorbit python2.4-pyxattr python2.4-reportlab python2.4-simpletal
                python2.4-soappy python2.4-sqlite python2.4-syck python2.4-unit
                python2.4-xlib python2.4-xml python2.4-xmpp quanta rdiff-backup reportbug
                secpolicy skim soundkonverter superkaramba thunderbird-locale-en-gb
                ubuntu-base ubuntu-minimal wlassistant ytalk
            4. Contributeur
              @Yoanbonche, essaye de lancer ton python par: python2.4

              et re-essaye tkinter, sinon tente le coups avec python2.5
            5. Modérateur
              @raspouteCa marche avec python 2.5 :)
              Si je ne peux pas virer 2.4 alors peut-être puis-je demander à ce que taper python exécute python 2.5 ?
          4. Modérateur
            Je sais que j'avais déjà installé Tcl/Tk par adept, donc apparemment ça ne change rien.

            apt-get install --reinstall python-tk suivi d'une réinstallation de python ne donne rien non plus :-/
            1. salut essaie d'installer tcl-Tk et ensuite de réinstaller python

              python sur linux n'est pas necessairement installé avec Tk alors qu'avec tcl oui. le fait de reinstaller python apres devrait lui permettre de reconnaitre Tk

              j'en suis pas vraiment sur... mais j'ai deja résolu ce probleme comme ça