No module named tkinter

If you get the Python error "No module named "tkinter", a solution is shown in this article. This usually means the module tkinter is not installed in your virtual environment.

Environment introduction

This error can appear on any Python installation. This is the system I used:

  • Ubuntu: 20.0
  • Python: 3.6.9
  • Switch between different Python environments based on virualenv

Related course: Python Desktop Apps with Tkinter

When it occurs

This can occur when the module is not installed. Sometimes you use another module that depends on it, like matplotlib.

import tkinter 

If this fails your Python may not be configured for Tk

ImportError: No module named tkinter


To solve it you can use your Linux distributions package manager. For Debian or Ubuntu Linux:

sudo apt-get install python3-tk 

If you use Fedora Linux:

sudo dnf install python3-tkinter

What is tkinter tcl ,tk?

The tkinter package (Tk interface) is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.)

You can check that tkinter is properly installed on your system by running python -m tkinter from the command line; this should open a window demonstrating a simple Tk interface.

tkinter is actually the standard Python to call tcl programs. You can call tcl's program through this interface, because there are many tcl programs and commands built into most unix systems.

Tcl is the abbreviation of "Tool Command Language", and its object-oriented is otcl Language. Tk is Tcl "graphics tool"Box" extension, it provides a variety of standard GUI interface items to facilitate rapid advanced application development.

tkinter vs Tkinter

When Python 3 came out, the Tkinter module was renamed to tkinter.

    # for Python2
    from Tkinter import *   ## notice capitalized T in Tkinter 
except ImportError:
    # for Python3
    from tkinter import *   ## notice lowercase 't' in tkinter here

Related course: Python Desktop Apps with Tkinter