#1 Le 11/10/2020, à 15:54
- xunil2003
Python 3 tkinter ne fonctionne pas sur ma machine
Bonjour,
Je suis sur Ubuntu 18.04 X64
Je n'arrive pas a faire fonctionner Python 3 avec tkinter
Dans un script bidon pour effectuer un test, j'ai :
#!/usr/bin/python3
from tkinter import *
fenetre = Tk()
label = Label(fenetre, text="Test")
label.pack()
fenetre.mainloop())
lorsque je l’exécute, j'ai ce message :
laurent@Laurent-I7-9900K:~$ python /home/laurent/Langages/python/3/test-01.py
Traceback (most recent call last):
File "/home/laurent/Langages/python/3/test-01.py", line 6, in <module>
from tkinter import *
ImportError: No module named tkinter
laurent@Laurent-I7-9900K:~$
Ors je ne comprends pas pourtant python est installé :
laurent@Laurent-I7-9900K:~$ ls -alh /usr/bin/python*
lrwxrwxrwx 1 root root 9 nov. 28 2019 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root 9 nov. 28 2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3,5M juil. 20 17:37 /usr/bin/python2.7
lrwxrwxrwx 1 root root 33 juil. 20 17:37 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 16 avril 16 2018 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root 9 nov. 28 2019 /usr/bin/python3 -> python3.6
-rwxr-xr-x 2 root root 4,4M juil. 17 14:50 /usr/bin/python3.6
lrwxrwxrwx 1 root root 33 juil. 17 14:50 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
-rwxr-xr-x 2 root root 4,4M juil. 17 14:50 /usr/bin/python3.6m
lrwxrwxrwx 1 root root 34 juil. 17 14:50 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
lrwxrwxrwx 1 root root 16 oct. 25 2018 /usr/bin/python3-config -> python3.6-config
lrwxrwxrwx 1 root root 10 nov. 28 2019 /usr/bin/python3m -> python3.6m
lrwxrwxrwx 1 root root 17 oct. 25 2018 /usr/bin/python3m-config -> python3.6m-config
lrwxrwxrwx 1 root root 16 avril 16 2018 /usr/bin/python-config -> python2.7-config
laurent@Laurent-I7-9900K:~$
Versions de python installé :
laurent@Laurent-I7-9900K:~$ python -V
Python 2.7.17
laurent@Laurent-I7-9900K:~$
laurent@Laurent-I7-9900K:~$ python3 -V
Python 3.6.9
laurent@Laurent-I7-9900K:~$
Module tkinter de python 3
laurent@Laurent-I7-9900K:~$ sudo apt-get install python3-tk
[sudo] Mot de passe de laurent :
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
python3-tk est déjà la version la plus récente (3.6.9-1~18.04).
python3-tk passé en « installé manuellement ».
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
libllvm9 libllvm9:i386 libnvidia-cfg1-440 libnvidia-common-435 libnvidia-common-440 libnvidia-compute-440 libnvidia-compute-440:i386 libnvidia-decode-440
libnvidia-decode-440:i386 libnvidia-encode-440 libnvidia-encode-440:i386 libnvidia-extra-440 libnvidia-fbc1-440 libnvidia-fbc1-440:i386 libnvidia-gl-440 libnvidia-gl-440:i386
libnvidia-ifr1-440 libnvidia-ifr1-440:i386 linux-hwe-5.4-headers-5.4.0-45 nvidia-compute-utils-440 nvidia-dkms-440 nvidia-kernel-common-440 nvidia-kernel-source-440
nvidia-utils-440 xserver-xorg-video-nvidia-440
Veuillez utiliser « sudo apt autoremove » pour les supprimer.
0 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour.
laurent@Laurent-I7-9900K:~$
Merci.
Dernière modification par xunil2003 (Le 11/10/2020, à 16:16)
- AMD R9 5950x 64 Go Ram / Intel Pentium I7 960 - 12 Go Ram - 6 T0 - Kubuntu 12.04 x64 / Kubuntu 14.04 x64 / Kubuntu 16.04 x64 / Kubuntu 18.04 x64 / Kubuntu 20.04 x64 / Mint
- DreamPlug Multi Boot / Marvel 1.22 Ghz / Architecture ARM / 512 Mo Ram / Carte-sd 16 Go class 10 / 5 Watts / Debian Squeeze 2.6.39.4
- Raspberry PI 1 / Raspberry PI 2 / Raspberry PI 3 / Raspberry PI 4 : 4Gb
JE SUIS CHARLIE
Hors ligne
#2 Le 11/10/2020, à 16:24
- xunil2003
Re : Python 3 tkinter ne fonctionne pas sur ma machine
Bonjour,
J'ai trouvé
Il fallait exécuté python de cette manière :
python3 /home/laurent/Langages/python/3/test-01.py
Excusez moi de dérangement.
Merci.
- AMD R9 5950x 64 Go Ram / Intel Pentium I7 960 - 12 Go Ram - 6 T0 - Kubuntu 12.04 x64 / Kubuntu 14.04 x64 / Kubuntu 16.04 x64 / Kubuntu 18.04 x64 / Kubuntu 20.04 x64 / Mint
- DreamPlug Multi Boot / Marvel 1.22 Ghz / Architecture ARM / 512 Mo Ram / Carte-sd 16 Go class 10 / 5 Watts / Debian Squeeze 2.6.39.4
- Raspberry PI 1 / Raspberry PI 2 / Raspberry PI 3 / Raspberry PI 4 : 4Gb
JE SUIS CHARLIE
Hors ligne
#3 Le 10/11/2020, à 22:33
- WW
Re : Python 3 tkinter ne fonctionne pas sur ma machine
Bonjour xunil2003,
Peux-tu éditer le sujet du topic pour y ajouter [Résolu], stp ?
Sinon quand tu mets en première ligne un shebang #!/usr/bin/python3 c'est fait pour ne pas avoir à se poser la question de l'interpréteur à utiliser.
Il faut donner les droits d'exécution à ton script avec :
chmod +x test-01.py
puis le lancer via un chemin relatif :
./test-01.py
ou absolu :
~/Langages/python/3/test-01.py
Autre remarque, il est préférable d'utiliser env pour le shebang c'est plus portable et c'est notamment nécessaire si tu veux pouvoir utiliser ton script dans et hors virtual env. Le shebang s'écrit alors #!/usr/bin/env python3
Cordialement
Quand on sait c'est facile, mais qui n'a jamais été débutant.
Hors ligne