Search code examples
pythonpython-3.xdatetimepython-dateutil

How to use dateutil.relativedelta in Python 3.x?


Hello I am trying to use relativedelta from the dateutil module.

I want to do what is mentioned here, add some months to a given datetime object.

But I'm trying to use Python 3 for this and I am getting the following error:

Traceback (most recent call last):
  File "bin/controller.py", line 2, in <module>
    from dateutil.relativedelta import relativedelta
ImportError: No module named 'dateutil'

I then read that dateutil is now part of Python 3 but how do I import it? import dateutil does not seem to work:

Traceback (most recent call last):
  File "bin/controller.py", line 3, in <module>
    import dateutil
ImportError: No module named 'dateutil'

I am using a virtualenv so I would like to install it with pip.


Solution

  • It seems you have to pip-install it like this and it works :

    pip install python-dateutil