0

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:

  1. 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).

  2. I also double checked the path variable and it was set correctly.

  3. I uninstalled python and reinstalled it.

  4. I checked to see if tkinter is in the folder C:\Python33\Lib\, and it is.

  5. I do have a mainloop() in my program.

  6. In my program, tkinter is all lowercase.

  7. 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?

MattDMo
  • 100,794
  • 21
  • 241
  • 231
user3071586
  • 3
  • 1
  • 2
  • 1
    Do you have Python 2.x installed anywhere on your system? –  Dec 05 '13 at 19:11
  • I just checked, it appears I only have Python 3.3, I couldn't find any other version on my computer. – user3071586 Dec 05 '13 at 19:15
  • Maybe you have to set PYTHONPATH - see more [How to add to the pythonpath in windows 7?](http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7) – furas Dec 05 '13 at 19:16
  • I didn't work after setting the PYTHONPATH. I created a new path called PYTHONPATH with C:\Python33\, I also tried C:\Python33\Lib. I even tried the suggestion at: http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7, what do you have in your PYTHONPATH variable? – user3071586 Dec 05 '13 at 19:26
  • That worked for me, the file runs now when I double click it. Thanks for your help! – user3071586 Dec 05 '13 at 19:49

2 Answers2

2

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:

  1. Right-click a .py file.

  2. In the menu that pops up, go to Open with.

  3. In the submenu that pops up, click on Choose default program...

  4. A window will then appear. In this window, click on the Browse... button.

  5. 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.)

  6. 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.

hon2a
  • 7,006
  • 5
  • 41
  • 55
0

This is actually a simple solution. You have:

    from tkinter import *

You need:

    from Tkinter import *

Capitalization is very specific!!!