0

I have just installed Python 3.4.0 on Windows. PATH is set properly, the trailing slash in C:\Python34\ removed, but I am having trooble running some scripts from an external file.

For example, I have found a hello world script for Tkinter. For argument, the simplest version is:

import tkinter
root = tkinter.Tk()

If I run each line individually in the prompt, it runs fine and it opens the window. If I save it in a file and try to run "python my_file.py" in the prompt, I get the following error:

AttributeError: 'module' object has no attribute 'Tk'

in line 2. I get strange errors trying to do stuff like

from tkinter.constants import *

or even

import sys

but only when I run from a file. Stuff like

print("Hello world")

runs just fine either way, so I think PATH is doing fine. What gives?

3
  • 3
    What are the "strange errors" you're getting? Please edit your question to include as much info as possible. Commented May 8, 2014 at 21:39
  • 3
    Also, the standard question when people get mysterious AttributeErrors: did you happen to name a program of your own tkinter.py? You can check by doing import tkinter and then print(tkinter.__file__). Commented May 8, 2014 at 22:11
  • I was gonna edit and include more detail, but then I read @DSM 's response and that was it. Thank you both Commented May 9, 2014 at 13:26

1 Answer 1

1

It sounds like you have a local file named "tkinter.py" that is getting imported when you do "import tkinter". You can verify that pretty easily with the following:

import tkinter
print(tkinter.__file__)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that was it, as DSM pointed out above. It was the name of the helloworld script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.