2016-09-21 5 views
0

Ich habe Probleme beim Ausführen von matplotlib.pyplot und tkinter mit python3.5. Ich bin auf Ubuntu 12.04.5 LTS. Ich sehe, dass python3-tk installiert ist, wenn ich dpkg -l python3-tk eintippe. Wie sonst sollte ich Fehler beheben?Importfehler mit Tkinter und python3.5

Ist python3-tk nur für python3.2 nicht python3.5?

Beispiele unten mit python3.2 gegen 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 ist

installiert
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

Ich vermute, dass _tkinter.so, kompiliert von _tkinter.c, ist irgendwo in/usr/bin/python3 und muss auch an der entsprechenden Stelle in /usr/bin/python3.5 sein. Ob es für 3.5 neu kompiliert werden muss (wie es unter Windows der Fall wäre) oder einfach kopiert werden, weiß ich nicht. –

Antwort

0

Die python3-tk-Bibliotheken unter der Version 3.2 installiert wurden, nicht mehr als 3,5. Python3-tk wurde deinstalliert und python3.5-tk wurde stattdessen installiert

1
sudo apt-get install python3-tk 

Dieser Befehl wird nur tkinter für Ihren Standard-python3 installieren, so python3.5 Import.

Sie können den folgenden Befehl ausführen für python3.5

sudo apt-get install python3.5-tk 
0

ändern Sie den matplotlib Backend zu 'agg' oder eine andere nicht-interaktive Option zu installieren. Etwas wie folgt aus:

matplotlib.use ('agg')

More info here (im Rahmen der Docker, wo ich dieses Problem konfrontiert und löste es erfolgreich):