Reputation: 13
I am running Windows 7 and have Python 3.3 64 bit installed. I seem to have a problem importing the tkinter module, I can import it fine through the python IDLE and it will work, but when I save the .py file and double click it, a cmd window will open and say:
Traceback (most recent call last):
File "C:Users\username\Desktop\g.py", line 3, in <module>
from tkinter import *
ImportError: No module named tkinter
I have tried the following:
I have tried import tkinter
, from tkinter import *
, and import tkinter as tk
and they don't seem to work when the .py
file is opened directly (double clicked).
I also double checked the path variable and it was set correctly.
I uninstalled python and reinstalled it.
I checked to see if tkinter is in the folder C:\Python33\Lib\, and it is.
I do have a mainloop()
in my program.
In my program, tkinter is all lowercase.
I tried a lot of solutions online from other posts, and they didn't work for me.
The top of my code is:
import sys
from tkinter import *
I don't know what I am missing, any suggestions?
Upvotes: 1
Views: 3012
Reputation: 76
This is actually a simple solution. You have:
from tkinter import *
You need:
from Tkinter import *
Capitalization is very specific!!!
Upvotes: 0
Reputation:
I'm going to make this an answer then for anybody in the future.
The problem is that Windows is currently set to run all .py
files with a different executable (probably a Python 2.x one) To fix the problem, follow these steps:
Right-click a .py
file.
In the menu that pops up, go to Open with
.
In the submenu that pops up, click on Choose default program...
A window will then appear. In this window, click on the Browse...
button.
Then, go find the Python execuatble. It should be at C:\Python33\python3.3.exe
. (There might be multiple pythonX.exe
files. If one doesn't work, try another.)
Once you select it, click Open
.
If done correctly, this procedure will manually reset the default executable for .py
files to be the Python 3.x one. Meaning, your script should run fine now.
Upvotes: 3