Tkinter Not Found

30,546

Solution 1

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()

Solution 2

ImportError: No module named 'Tkinter' In Python 3 Tkinter is changed to tkinter Try import tkinter as tk

Hope it helps!

Share:
30,546
CodeMonkey
Author by

CodeMonkey

Autonomous Vehicle Software Engineer for General Motors Corporation

Updated on July 09, 2022

Comments

  • CodeMonkey
    CodeMonkey almost 2 years

    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!

  • CodeMonkey
    CodeMonkey over 10 years
    Typing "python" in a command prompt shows: Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
  • falsetru
    falsetru over 10 years
    @CodeMonkey, I updated the answer. Once, run it by double-clicking and run it in command.
  • CodeMonkey
    CodeMonkey over 10 years
    But we both do have two versions installed. As for capitalization... it turns out that my tkinter folder contains neither tkinter nor Tkinter. So... where's it really coming from?
  • falsetru
    falsetru over 10 years
    @CodeMonkey, It's in C:\python3.3\Lib\tkinter (Python 3.3), C:\Python27\Lib\lib-tk\Tkinter.py if you didn't changed the installation directory.
  • falsetru
    falsetru over 10 years
    @CodeMonkey, Try python -c "import tkinter; print(tkinter.__file__)" or python -c "import Tkinter; print(Tkinter.__file__)". Then, you can find where the module come from.
  • CodeMonkey
    CodeMonkey over 10 years
    Very very interesting... That might get me on the right path :-) 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
  • CodeMonkey
    CodeMonkey over 10 years
    I removed Python33 from PATH and now command prompt shows it is using 2.6.5. However, it's still not finding Tkinter. So basically, same problem
  • CodeMonkey
    CodeMonkey over 10 years
    I've added Python33 back to PATH and imported tkinter instead of Tkinter. Still doesn't find it in command prompt. I changed it so .py opens with Python33 and it doesn't work either.
  • falsetru
    falsetru over 10 years
    @CodeMonkey, What do you get with the following command in command line? python -c "import Tkinter; print(Tkinter.__file__)"
  • CodeMonkey
    CodeMonkey over 10 years
    ImportError: No module named 'Tkinter'
  • falsetru
    falsetru over 10 years
    @CodeMonkey, I think you installed Python 2.6 without Tkinter. If possible, reinstall Python 2.6 with Tkinter.
  • CodeMonkey
    CodeMonkey over 10 years
    I have a mystical "Python Launcher For Windows" application that runs my scripts on double-click. It uses python 2.6.5 and is the only application that works. If I select any other python.exe (even 2.6.5), the script fails. Typing the application in Start>Search, it claims it resides in C:\Python33 and that it's really python.exe.
  • falsetru
    falsetru over 10 years
    @CodeMonkey, Make a script with import sys; print(sys.executable) as content. Run it in command line and by using "Python Launcher For Windows". And please let me know result of both run.
  • CodeMonkey
    CodeMonkey over 10 years
    Well, it printed out yet another version of python (these machines have way too much stuff installed :-p). Using that version for command prompt actually works! Oddly enough, however, selecting the version directly for opening .py files does not work. At any rate, I believe with all this info combined, it has resolved my issue. Thanks!!