I have an Anaconda environment with python 3.9.1 and I'm getting the following error message when I try to import tkinter.
Traceback (most recent call last): File "/Users/isevilla/opt/miniconda3/envs/lab/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3418, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-2-537f0be70a2b>", line 1, in <module> runfile('/Users/isevilla/Documents/Tkinter playground/tkinter.py', wdir='/Users/isevilla/Documents/Tkinter playground') File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/isevilla/Documents/Tkinter playground/tkinter.py", line 1, in <module> import tkinter as tk File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/Users/isevilla/Documents/Tkinter playground/tkinter.py", line 4, in <module> root = tk.Tk() AttributeError: partially initialized module 'tkinter' has no attribute 'Tk' (most likely due to a circular import)
The error pops up when I'm trying to run the following simple code:
import tkinter as tk root = tk.Tk() myLabel = tk.Label(root, text='Hello world') myLabel.pack() root.mainLoop()
Does someone know why this happen and how can I fix it?
https://stackoverflow.com/questions/65802471/circular-import-generating-an-attributeerror-when-importing-tkinter January 20, 2021 at 10:59AM
没有评论:
发表评论