Tkinter Not Found

CodeMonkey picture CodeMonkey · Sep 26, 2013 · Viewed 26.7k times · Source

I'm running Windows 7 32-bit. I've installed Python 3.2.2 and selected every module for installation (including Tcl/Tk). On my computer, I can run a script by double-clicking the .py file and it will find my Tkinter import just fine. If I run it from a command line, it says ImportError: No module named 'Tkinter'. I passed this script on to a coworker who also installed the same way, and she can't run the script at all even with double-clicking. Same Tkinter problem. Our PATHs are identical with C:\Python33 being the first item and tkinter shows in the lib folder. I'm running out of ideas. What's going on? Why is Tkinter so finicky with existing?

Update: Apparently Tcl/Tk do not include Tkinter. The reason it worked for me was because I had installed a special Python package via our company's download system that happened to include it. This version was linked to .py extensions. In command prompt, however, my updated Python (with Tcl/Tk but without Tkinter) was the python of choice as selected by my PATH variable. My coworker did not have this special package installed so it did not work for her. I had thought it was my Python 3.3 that was running the script but it was not which is why it seemed like it worked for me. That said, if anyone else runs into this issue, check out the sys.executable and sys.version as indicated below to figure out just what is going on!

Answer

falsetru picture falsetru · Sep 26, 2013

You may have both Python 2.x and Python 3.x. And py extension is linked to Python 2.x interpreter. And your python script is designed to run with Python 2.x.

In Python 3, Tkinter module was renamed to tkinter (lowercase).


Make a script as follow, then run it by clicking it, and run it in command. You may get different results:

import sys
print(sys.version)
input()