tkcalendar
tkcalendar copied to clipboard
Cannot Import 'Calendar' Due To Circular Import
I am trying to run the example code given on the main page and I am getting the following import error:
ImportError: cannot import name 'Calendar' from partially initialized module 'tkcalendar' (most likely due to a circular import) (C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\__init__.py)
Full stack trace:
Traceback (most recent call last):
File "calendar.py", line 9, in <module>
from tkcalendar import Calendar, DateEntry
File "C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\__init__.py", line 26, in <module>
from tkcalendar.dateentry import DateEntry
File "C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\dateentry.py", line 35, in <module>
from tkcalendar.calendar_ import Calendar
File "C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\calendar_.py", line 27, in <module>
import calendar
File "C:\Users\Dan\Desktop\True Gravity Baseball\calendar.py", line 9, in <module>
from tkcalendar import Calendar, DateEntry
ImportError: cannot import name 'Calendar' from partially initialized module 'tkcalendar' (most likely due to a circular import) (C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\__init__.py)
I've tried a number of potential solutions and nothing seems to work.
Any ideas on how to resolve this would be greatly appreciated. Thanks! :)
Could you describe some of the potential solutions you've tried so far? What's your env looking like? Are you using the latest version?
I'm had exactly the same issue when running the example code.. This was due to the filename I had for the test.. "calendar.py"..
SOLUTION: Rename this file to whatever else, solved the issue and the calendar functionality is working.
I'm running :
- Windows 10
- Python 3.10.8
- tkcalendar 1.6.1
Little output in case someone needs it for development:
(venv) c:\factorialApp>python calendar.py
Traceback (most recent call last):
File "c:\factorialApp\calendar.py", line 1, in <module>
from tkcalendar import Calendar, DateEntry
File "C:\factorialApp\venv\lib\site-packages\tkcalendar\__init__.py", line 26, in <module>
from tkcalendar.dateentry import DateEntry
File "C:\factorialApp\venv\lib\site-packages\tkcalendar\dateentry.py", line 35, in <module>
from tkcalendar.calendar_ import Calendar
File "C:\factorialApp\venv\lib\site-packages\tkcalendar\calendar_.py", line 27, in <module>
import calendar
File "c:\factorialApp\calendar.py", line 1, in <module>
from tkcalendar import Calendar, DateEntry
ImportError: cannot import name 'Calendar' from partially initialized module 'tkcalendar' (most likely due to a circular import) (C:\factorialApp\venv\lib\site-packages\tkcalendar\__init__.py)
(venv) c:\factorialApp>python calendar.py
Traceback (most recent call last):
File "c:\factorialApp\calendar.py", line 1, in <module>
from tkcalendar import DateEntry
File "C:\factorialApp\venv\lib\site-packages\tkcalendar\__init__.py", line 26, in <module>
from tkcalendar.dateentry import DateEntry
File "C:\factorialApp\venv\lib\site-packages\tkcalendar\dateentry.py", line 35, in <module>
from tkcalendar.calendar_ import Calendar
File "C:\factorialApp\venv\lib\site-packages\tkcalendar\calendar_.py", line 27, in <module>
import calendar
File "c:\factorialApp\calendar.py", line 1, in <module>
from tkcalendar import DateEntry
ImportError: cannot import name 'DateEntry' from partially initialized module 'tkcalendar' (most likely due to a circular import) (C:\factorialApp\venv\lib\site-packages\tkcalendar\__init__.py)
Versions via pip:
(venv) c:\factorialApp>pip install --upgrade tkcalendar
Requirement already satisfied: tkcalendar in c:\factorialapp\venv\lib\site-packages (1.6.1)
Requirement already satisfied: babel in c:\factorialapp\venv\lib\site-packages (from tkcalendar) (2.10.3)
Requirement already satisfied: pytz>=2015.7 in c:\factorialapp\venv\lib\site-packages (from babel->tkcalendar) (2022.2.1)
This happens because you called your script like the standard library module calendar
which tkcalendar
uses. Python checks your project files and folders first when trying to load modules and thus the circular import is created. This is not an issue with this project, just rename your file to something else and it should work