Install tkinter in python3.6 on Ubuntu
run from terminal:
sudo apt-get install python3.6-tk
or just reinstall completly:
sudo apt-get install python3.6
Python version 3.6.4 (Ubuntu 18.04 LTS)
sudo add-apt-repository main
sudo apt-get install python3-tk
I faced a similar problem to yours, I am giving the details of it and how I solved it.
On Ubuntu 16.04 LTS, I have Python 3.5.2 and Python 2.7.12 but I would like to experiment Python3.6 (for various reasons like this one, for example). So I relied on this post:
sudo add-apt-repository ppa:deadsnakes/ppasudo apt-get updatesudo apt-get install python3.6
When I tried to run a module using tkinter, I got this error message:
Traceback (most recent call last): File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module> import _tkinterModuleNotFoundError: No module named '_tkinter'During handling of the above exception, another exception occurred:Traceback (most recent call last): File "bill.py", line 3, in <module> from tkinter import Canvas, Label, Tk, StringVar, Button, LEFT File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module> raise ImportError(str(msg) + ', please install the python3-tk package')ImportError: No module named '_tkinter', please install the python3-tk package
I tried to install tkinter as the message above asks:
sudo apt-get install python3-tk[sudo] password for begueradj: Reading package lists... DoneBuilding dependency tree Reading state information... Donepython3-tk is already the newest version (3.5.1-1).0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Obviously, I still can not use tkinter for Python 3.6. How to fix this problem?
My first blind attempt did not work:
sudo apt-get install python36-tkReading package lists... DoneBuilding dependency tree Reading state information... DoneE: Unable to locate package python36-tk
The second one works:
sudo apt-get install python3.6-tkReading package lists... DoneBuilding dependency tree Reading state information... DoneSuggested packages: tix python3.6-tk-dbgThe following NEW packages will be installed: python3.6-tk0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.Need to get 74.6 kB of archives.After this operation, 165 kB of additional disk space will be used.Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 python3.6-tk amd64 3.6.5-1+xenial1 [74.6 kB]Fetched 74.6 kB in 0s (301 kB/s) Selecting previously unselected package python3.6-tk:amd64.(Reading database ... 324106 files and directories currently installed.)Preparing to unpack .../python3.6-tk_3.6.5-1+xenial1_amd64.deb ...Unpacking python3.6-tk:amd64 (3.6.5-1+xenial1) ...Setting up python3.6-tk:amd64 (3.6.5-1+xenial1) ...
And that solved my problem:
~/python3.6Python 3.6.5 (default, Mar 29 2018, 03:28:50) [GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import tkinter>>>