[Python] AttributeError: module 'datetime' has no attribute 'now'

Discussão em 'Python' iniciado por Stack, Julho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have this Python code:

    import datetime

    print(type(datetime))
    d1 = datetime.datetime.now()
    print(d1)


    when I running the code using Pycharm and Sublime I get errors.

    Here is the error on Sublime:

    <class 'module'>
    Traceback (most recent call last):

    File "D:\programming\python\datetime.py", line 1, in <module>
    import datetime

    File "D:\programming\python\datetime.py", line 4, in <module>
    d1 = datetime.datetime.now()

    AttributeError: module 'datetime' has no attribute 'now'


    Here is the error on Pycharm:

    D:\programming\python\venv\Scripts\python.exe C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevconsole.py" 63029 63030
    <class 'module'>
    Traceback (most recent call last):

    File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevconsole.py", line 4, in <module>
    from _pydev_imps._pydev_saved_modules import thread

    File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\_pydev_imps\_pydev_saved_modules.py", line 21, in <module>
    import xmlrpc.client as xmlrpclib

    File "D:\programming\Anoconda3\lib\xmlrpc\client.py", line 134, in <module>
    from datetime import datetime

    File "D:\programming\python\datetime.py", line 4, in <module>
    d1 = datetime.datetime.now()

    AttributeError: module 'datetime' has no attribute 'now'
    Process finished with exit code 1


    This code is running well under IDLE and cmd. And it's running well when I just do print(type(datetime)), but that code just prints the type of datetime twice.

    Continue reading...

Compartilhe esta Página