ImportError: No module named '_tkinter', please install the python3-tk package
The python3-tk package has support for python versions 3.6 and 3.7, not 3.5, which is your default. Change your default python to a version supported if your work supports that. Otherwise, if you really need version3.5, you will need to track down the support files.
Related videos on Youtube
Martin Thoma
I also have a blog about Code, the Web and Cyberculture and a career profile on Stackoverflow. My interests are mainly machine-learning, neural-networks, data-analysis.
Updated on September 18, 2022Comments
-
Martin Thoma over 1 year
After an
sudo apt-get upgrade
, I get the following error:Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] 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
I have
python3-tk
installed. I already tried purging and installing it. Doesn't change anything. (Interestingly, the/usr/lib/python3.5/tkinter
still existed after pruging... and manually removing it did only lead to another error)How can I fix this problem?
Did not solve the problem:
$ sudo apt-get install tk8.6-dev $ sudo apt-get install python3-tkinter # does not exist $ sudo apt-get install python3-tk # exists and is installed
Comment answers
$ ls -l /usr/lib/python3.5/tkinter total 372 -rw-r--r-- 1 root root 1791 Nov 28 17:50 colorchooser.py -rw-r--r-- 1 root root 1412 Nov 28 17:50 commondialog.py -rw-r--r-- 1 root root 1493 Nov 28 17:50 constants.py -rw-r--r-- 1 root root 1568 Nov 28 17:50 dialog.py -rw-r--r-- 1 root root 11488 Nov 28 17:50 dnd.py -rw-r--r-- 1 root root 14502 Nov 28 17:50 filedialog.py -rw-r--r-- 1 root root 6581 Nov 28 17:50 font.py -rw-r--r-- 1 root root 162249 Nov 28 17:50 __init__.py -rw-r--r-- 1 root root 148 Nov 28 17:50 __main__.py -rw-r--r-- 1 root root 3701 Nov 28 17:50 messagebox.py drwxr-xr-x 2 root root 4096 Nov 30 08:12 __pycache__ -rw-r--r-- 1 root root 1814 Nov 28 17:50 scrolledtext.py -rw-r--r-- 1 root root 11424 Nov 28 17:50 simpledialog.py -rw-r--r-- 1 root root 77014 Nov 28 17:50 tix.py -rw-r--r-- 1 root root 55839 Nov 28 17:50 ttk.py
When moving the directory, I get:
$ sudo mv tkinter tkinter-backup $ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'tkinter'
More info
$ which python3 /usr/bin/python3 $ apt list python3 Listing... Done python3/xenial,now 3.5.1-3 amd64 [installed]
-
Steve almost 6 yearsWhat do you see if you run
ls -l /usr/lib/python3.5/tkinter
? You say that you manually removed it resulting in another error, what was that error? -
Steve almost 6 yearsWhere is your python installation from? Can you run
which python3
andapt list python3
? -
Martin Thoma almost 6 years@Steve See edited question for the answers
-
WinEunuuchs2Unix over 5 yearsPossible duplicate of ImportError: No named '_tkinter', please install the python3-tk package
-
-
WinEunuuchs2Unix over 4 yearsCapital T is for Python 2.7.12. OP is trying to use Python 3.x.