No module named 'tkinter' (Python3.8) in Windows

Viewed 6642

I have Python3.8.7 and my operating system is Windows. I know that Tkinter module is in the standard library so we don't need to install it. But when I try to import it:

the image that shows the terminal

I also tried to install it: the installing image

(I also looked at the other question in StackOverflow, but it was for Linux and I didn't solve my problem. And also it is too old.)

EDIT: I solved this problem. I executed the installer again and chose the "Modify" option and after that, I chose the "Repair" option. And my problem was solved!

4 Answers

Just re-install python..

tkinter (and the associated system libraries it needs) are meant to be included by default with any version of python you install. If it got deleted or corrupted (or not installed in the first place), it is easiest often just to re-install python. If you want to keep all the libraries you've already installed, copy c:\Python38\Lib\site-packages somewhere safe, then you can go ahead and delete the python folder. Next you'll want to search using the start menu for "environment variables", and select "edit environment variables for your account". Select the "Path" variable, and click the "edit" button. Delete any entries referring back to the python folder you just deleted.remove old references to the old python installation from the system search path

The recommended windows installer from python.org for 3.8.7 includes several options if you "customize installation" including whether or not to install tkinter as well as where you want to install.python 3.8.7 64 bit windows installerChecking the entry for "add to PATH" will ensure that when you type "python" into a cmd prompt; it works. You can then move your old "site-packages" folder back to your python folder in the same location "pyfolder\Lib\site-packages". If you install a different version of python you should re-install any libraries rather than copying them, but saving site-packages will at least give you a list of what you need to go install.

I also had the same problem (on Windows 10) but with python 3.10.0. PyCharm could not install it for me, it suggested installing Future for some reason. The following solved the problem for me:

(I still had the python installer exe among my Downloads. If you do not have it, download it from here.)

Run the installer, choose Modify (Add or remove individual features), tick tcl/tk and IDLE.

I did not have to edit my PATH or re-install previously installed modules.

Well I can see one solutions here:

  1. Follow the Docs-Tkinter install for Python (for Windows):

Tkinter (and, since Python 3.1, ttk) are included with all standard Python distributions. It is important that you use a version of Python supporting Tk 8.5 or greater, and ttk. We recommend installing the "ActivePython" distribution from ActiveState, which includes everything you'll need.

In your web browser, go to Activestate.com, and follow along the links to download the Community Edition of ActivePython for Windows. Make sure you're downloading a 3.1 or newer version, not a 2.x version.

Run the installer, and follow along. You'll end up with a fresh install of ActivePython, located in, e.g. C:\python32. From a Windows command prompt, or the Start Menu's "Run..." command, you should then be able to run a Python shell via:

% C:\python32\python

This should give you the Python command prompt. From the prompt, enter these two commands:

>>> import tkinter
>>> tkinter._test()
This should pop up a small window; the first line at the top of the window should say "This is Tcl/Tk version 8.5"; make sure it is not 8.4!

Have you tried using from Tkinter import * instead of import Tkinter? I think I can remember only from Tkinter import * worked for me.

Related