The Python Oracle

ImportError: No module named 'Tkinter'

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Magic Ocean Looping

--

Chapters
00:00 Importerror: No Module Named 'Tkinter'
00:30 Accepted Answer Score 671
01:06 Answer 2 Score 94
01:25 Answer 3 Score 65
01:52 Answer 4 Score 48
02:14 Thank you

--

Full question
https://stackoverflow.com/questions/2590...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #tkinter

#avk47



ACCEPTED ANSWER

Score 671


You probably need to install it using something similar to the following:

  • For Ubuntu or other distros with Apt:

    sudo apt-get install python3-tk
    
  • For Fedora:

    sudo dnf install python3-tkinter
    

You can also mention a Python version number like this:

  • sudo apt-get install python3.7-tk
    
  • sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64
    

Finally, import tkinter (for Python 3) or Tkinter (for Python 2), or choose at runtime based on the version number of the Python interpreter (for compatibility with both):

import sys
if sys.version_info[0] == 3:
    import tkinter as tk
else:
    import Tkinter as tk



ANSWER 2

Score 94


As you are using Python 3, the module has been renamed to tkinter, as stated in the documentation:

Note Tkinter has been renamed to tkinter in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.




ANSWER 3

Score 65


For Windows, make sure to check in the Python install the optional feature "tcl/tk and IDLE". Otherwise you get:

ModuleNotFoundError: No module named 'tkinter'

If Python is already installed without this optional feature, you need to amend the installation by launching again the Python installer and selecting Modify.

NB: you won't be able pip install tkinter, don't bother trying!




ANSWER 4

Score 48


To install the Tkinter on popular Linux distros:

Debian/Ubuntu:

sudo apt install python3-tk -y  

Fedora:

sudo dnf install -y python3-tkinter

Arch:

sudo pacman -Syu tk --noconfirm 

REHL/CentOS6/CentOS7:

sudo yum install -y python3-tkinter

OpenSUSE:

sudo zypper in -y python-tk