2016-09-21 1 views
0

J'ai des problèmes pour exécuter matplotlib.pyplot et tkinter avec python3.5. Je suis sur Ubuntu 12.04.5 LTS. Je vois que python3-tk est installé quand je tape dpkg -l python3-tk. Sinon, comment devrais-je résoudre le problème?Erreur d'importation avec Tkinter et python3.5

Est-ce que python3-tk est seulement pour python3.2 pas python3.5?

exemples ci-dessous avec python3.2 par rapport python3.5

machine:~$ /usr/bin/python3 
Python 3.2.3 (default, Jun 18 2015, 21:46:58) 
[GCC 4.6.3] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import tkinter 
>>> exit() 

machine:~$ /usr/bin/python3.5 
Python 3.5.2 (default, Jul 17 2016, 17:38:18) 
[GCC 4.6.3] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import tkinter 
Traceback (most recent call last): 
    File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module> 
    import _tkinter 
ImportError: No module named '_tkinter' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib/python3.5/tkinter/__init__.py", line 38, in <module> 
    raise ImportError(str(msg) + ', please install the python3-tk package') 
ImportError: No module named '_tkinter', please install the python3-tk package 

python3-tk est installé

machine:~$ dpkg -l python3-tk 
Desired=Unknown/Install/Remove/Purge/Hold 
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend 
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) 
||/ Name       Version      Description 
    +++-============================-============================- 

======================================================================== 
ii python3-tk     3.2.3-1      Tkinter - Writing Tk applications with Python 3.x 
+0

Je soupçonne que _tkinter.so, compilé à partir de _tkinter.c, se trouve quelque part dans/usr/bin/python3 et doit également se trouver à l'emplacement correspondant dans /usr/bin/python3.5. Que ce soit doit être recompilé pour 3.5 (comme ce serait le cas sur Windows) ou simplement copié, je ne sais pas. –

Répondre

0

Les bibliothèques python3-tk ont ​​été installés sous la version 3.2, pas 3.5. Python3-tk a été désinstallée et python3.5-tk a été installé à la place

1
sudo apt-get install python3-tk 

Cette commande installera tkinter pour votre défaut python3 seulement, donc python3.5 ImportError.

Vous pouvez exécuter la commande suivante pour installer pour python3.5

sudo apt-get install python3.5-tk 
0

Changer le backend matplotlib à 'AGG' ou une autre option non interactive. Quelque chose comme ce qui suit:

matplotlib.use ('agg')

More info here (dans le contexte de Docker, où je faisais face à ce problème et résolu avec succès):