Reputation: 195
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:
I also tried to install it:
(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!
Upvotes: 6
Views: 26016
Reputation: 618
I'm surprised by the proposed complex solutions here! It's simple as follows:
Modify
then check tcl/tkUpvotes: 0
Reputation: 21
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.
Upvotes: 2
Reputation: 11075
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.
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.Checking 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.
Upvotes: 5
Reputation: 201
Have you tried using from Tkinter import *
instead of import Tkinter
? I think I can remember only from Tkinter import *
worked for me.
Upvotes: -2