100
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> 

on the other hand...

Python 3.2 (r32:88445, Mar 25 2011, 19:28:28) 
[GCC 4.5.2] on linux2
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 

I checked synaptic, Tkinter is installed. Then I found this--

If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.

I am guessing that tkinter is still associated with the old python in my pc. How do I change that so python3 can use tkinter?

3
  • 19
    "sudo apt-get install python3-tk" installs tkinter for Python3+ Commented Oct 16, 2012 at 21:15
  • Does this answer your question? Difference between tkinter and Tkinter Commented Apr 26, 2023 at 15:19
  • "Then I found this" - that describes a different failure from what is actually seen in the code. Commented May 3, 2023 at 1:42

15 Answers 15

328

What worked for me in Ubuntu was actually just:

sudo apt-get install python3-tk

For python 3.6:

sudo apt-get install python3.6-tk

I didn't read anywhere, I simply tried it, as onteria_'s method didn't seem to work for me.

5
  • 8
    This package was indeed needed for me, but keep in mind that the name of Tkinter is now tkinter in Python3, so other answers are still relevant. Commented Mar 2, 2015 at 18:17
  • first command I get connection failed, the second one works fine though Commented Aug 27, 2018 at 11:54
  • 1
    I don't know what happened, sudo apt-get install python3-tk did not work for me (tkinter still not found), but installing python3-tk via synaptic did work. (Ubuntu 16.04 with python 3.6)
    – Georg
    Commented Nov 25, 2018 at 14:22
  • It still works. Well done
    – Dominiksr
    Commented Jun 11, 2022 at 9:59
  • 1
    Perhaps quite late, but I checked the output of apt-cache policy python3*-tk , it gave me python3-tk as the viable one, the entries for 3.10-tk and 3.11-tk were blank. Installing python3-tk worked for me. (Ubuntu22.04, Python 3.10.6)
    – Luce
    Commented Jan 26, 2023 at 2:30
40

The answer to your question is that Tkinter is renamed to tkinter in python3.

That is with lowercase t.

1
  • This is the actually correct answer based on what is actually shown in the original question. Everything else is making assumptions and solving a common problem, but not engaging with the issue actually shown in OP's actual attempt. Commented Apr 25, 2023 at 18:15
20

In python 3 Tkinter renamed tkinter

2
  • This is the answer to the question. PS: If you run your script with a shebang, don't forget to use "#!/usr/bin/python3". On Ubuntu 12.04 for example default version of Python is 2.7.3 so "Tkinter" will work with "#!/usr/bin/python" but not with Python 3. Commented Sep 28, 2013 at 12:43
  • Second that this is the best and simplest answer to the question Commented Jun 15, 2015 at 17:41
20

Use the following command:

sudo apt-get install python3-tk

The following commands do not work:

sudo apt-get install python3-tkinter
sudo apt-get install python3-Tkinter
pip3 install Tkinter
pip3 install tkinter
15
sudo apt-get install python3-tk
0
11

Since you mention synaptic I think you're on Ubuntu. You probably need to run update-python-modules to update your Tkinter module for Python 3.

EDIT: Running update-python-modules

First, make sure you have python-support installed:

sudo apt-get install python-support

Then, run update-python-modules with the -a option to rebuild all the modules:

sudo update-python-modules -a

I cannot guarantee all your modules will build though, since there are some API changes between Python 2 and Python 3.

6
  • 22
    "sudo apt-get install python-support" leads to the following error "E: Package 'python-support' has no installation candidate"
    – jason
    Commented Dec 9, 2016 at 1:04
  • 6
    I also had the same error as @jason E: Package 'python-support' has no installation candidate though I am running it from a docker (tensorflow image). Did anyone know how to fix it? Commented Apr 3, 2017 at 21:09
  • 18
    @CharlieParker On Ubuntu 16.04 LTS, I was able to fix this by apt-get install python3-tk
    – rohitmohta
    Commented Dec 3, 2017 at 19:44
  • For those of you with the E: Package 'X' has no installation candidate, you should run sudo apt-get update first. Commented Aug 1, 2018 at 10:01
  • is there a way I can do this in a gitpod too? it doesnt let me use sudo nor lets me do without it Commented Feb 7, 2021 at 6:24
9

If you are using Ubuntu 18.04 along with Python 3.6, then pip or pip3 won't help. You need to install tkinter using following command:

sudo apt-get install python3-tk
1
  • This merely seems to repeat multiple earlier answers from 2015-2017
    – tripleee
    Commented Mar 3, 2023 at 21:34
5

I had the same problem. I tried to use:

sudo apt-get install python3-tk

It gave an error stating blt(>=2.4z-7) is not present and is not installable.

I went here and manually installed it. (For Ubuntu 14.04)

Then I used apt again and it worked.

I concluded that python3.4 in Ubuntu didn't come with the .so file required to carry on installation. And blt was required to download it.

4

this works for me:

from tkinter import *
root = Tk()
l = Label(root, text="Does it work")
l.pack()
3

I found this looking for a fix for python 3.5.

In my case I was building python from source, here is what I did to help fix:

Add the tkinter headers with and rebuild python

sudo apt-get install tk8.6-dev
sudo make
2

Adding solution for CentOs 7 (python 3.6.x)

yum install python36-tkinter

I had tried about every version possible, hopefully this helps out others.

1

Adding the solution that I faced with python 3.4 on Fedora 21. Hope this will help those facing a similar issue.

Any of these commands will install tkinter:

sudo yum install python3-tkinter
OR
sudo dnf install python3-tkinter
0

requirement for tkinter:

python 3.6+

and go to shell write the test code like :

from tkinter import *

root = Tk()

root.mainloop()

enter image description here

0
0

For Ubuntu 22.04 this works for me.

sudo apt install python3-tk tk-dev

-1

For Ubuntu 20.04 this works for me.

sudo apt-get install python3.6-tk
3
  • 1
    This solution has already been provided.
    – AlexK
    Commented Dec 27, 2022 at 2:26
  • @AlexK but not for 20.04 Commented Jan 3, 2023 at 14:56
  • 1
    If an existing answer is still valid for a newer release, there is no need to post another answer.
    – AlexK
    Commented Jan 3, 2023 at 21:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.