Tkinter module not found on Ubuntu

Python 3.xTkinter

Python 3.x Problem Overview


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?

Python 3.x Solutions


Solution 1 - Python 3.x

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.

Solution 2 - Python 3.x

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

that is with lowercase t

Solution 3 - Python 3.x

In python 3 Tkinter renamed tkinter

Solution 4 - Python 3.x

sudo apt-get install python3-tk

Solution 5 - Python 3.x

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

Solution 6 - Python 3.x

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.

Solution 7 - Python 3.x

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

Solution 8 - Python 3.x

this works for me:

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

Solution 9 - Python 3.x

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.

Solution 10 - Python 3.x

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.

Solution 11 - Python 3.x

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

Solution 12 - Python 3.x

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

Solution 13 - Python 3.x

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJim SyyapView Question on Stackoverflow
Solution 1 - Python 3.xPinna_beView Answer on Stackoverflow
Solution 2 - Python 3.xNils NymanView Answer on Stackoverflow
Solution 3 - Python 3.xuser2569010View Answer on Stackoverflow
Solution 4 - Python 3.xRoberto JúniorView Answer on Stackoverflow
Solution 5 - Python 3.xKishan KishoreView Answer on Stackoverflow
Solution 6 - Python 3.xonteria_View Answer on Stackoverflow
Solution 7 - Python 3.xabhimanyu singhView Answer on Stackoverflow
Solution 8 - Python 3.xuser1497423View Answer on Stackoverflow
Solution 9 - Python 3.xMohit SinhaView Answer on Stackoverflow
Solution 10 - Python 3.xl Steveo lView Answer on Stackoverflow
Solution 11 - Python 3.xparsethisView Answer on Stackoverflow
Solution 12 - Python 3.xMaNKuRView Answer on Stackoverflow
Solution 13 - Python 3.xSarveshView Answer on Stackoverflow