Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter Not Found

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!

like image 895
CodeMonkey Avatar asked Sep 26 '13 14:09

CodeMonkey


2 Answers

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()
like image 184
falsetru Avatar answered Oct 03 '22 20:10

falsetru


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

Hope it helps!

like image 39
Ayush Raj Avatar answered Oct 03 '22 19:10

Ayush Raj