Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
importing datetime trouble
#1
I'm new here, so please excuse if this is posted in the wrong place. I've been trying to learn Python, using ver. 3.6.4, and for the most part am enthused about it. But I haven't been able to import datetime. What gives? When I first downloaded Py, it worked for me, but not in the last week or so.
Reply
#2
what happens when you import datetime? Do you get an error?
Recommended Tutorials:
Reply
#3
Yes, >>> import datetime
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import datetime
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\datetime.py", line 1, in <module>
import calendar
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\calendar.py", line 50, in <module>
class _localized_month:
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\calendar.py", line 52, in _localized_month
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\calendar.py", line 52, in <listcomp>
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
AttributeError: module 'datetime' has no attribute 'date'
>>>
Reply
#4
Are you calling your own script datetime.py? If so, rename it to something that can't be imported in vanilla Python.
Reply
#5
I though of playing with datetime and ended up creating file named: datetime.py

After couple of hours, I came across this post and realized what was wrong. Renamed my script file to datetime_xx and my issue was resolved.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 9,514 Sep-18-2019, 08:32 AM
Last Post: buran
  Trouble importing modules on a new python version snackman_barry 2 2,521 Jul-12-2019, 11:15 AM
Last Post: snackman_barry
  Trouble on importing function from astropy library samsonite 4 3,637 Mar-21-2019, 12:18 PM
Last Post: samsonite
  Trouble importing text from a .docx file atinesh922 3 3,884 Jan-03-2018, 06:35 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020