Reputation: 25
I am a novice about Python and Pycharm. I followed the tutorial wrote the code below:
This code can run well on IDLE. But can't run in Pycharm.
I searched online. The answers I found are about Pycharm interpreter setting. My interpreter setting is good. It can find the module. But when I run it, There are exceptions.
I spent several hours try to solve this problem, still don't know why.
Upvotes: 1
Views: 244
Reputation: 3450
Change your filename to somethingelse.py
EDIT (with a better explanation:)
What is happening here is that OP is trying to import tkinter
. However, since they have named their file "tkinter.py
," the interpreter thinks that this is the module OP is referencing. For this reason, OP is not getting the desired results, and instead is getting an error about missing attributes.
This probably worked for OP in the IDLE environment, because IDLE allows you to execute the code from within the environment as if you were in a terminal. Pycharm was trying to have the Python interpreter execute the .py file that OP had pulled up.
More information about how Python's import system works can be found here: https://docs.python.org/3/reference/import.html
Upvotes: 4