15

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.

Community
  • 1
  • 1
aairey
  • 310
  • 1
  • 3
  • 13

4 Answers4

14

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

pip install python-dateutil
acknowledge
  • 434
  • 6
  • 12
5

You need to install it first using pip3 install python-dateutil. It's not included by default with Python 3, I don't know where you read that.

I added a pip3 and not just plain old pip because that will install it specifically for Python 3.

noɥʇʎԀʎzɐɹƆ
  • 9,967
  • 2
  • 50
  • 67
3

Open up your console and type: pip install python-dateutil

A Magoon
  • 1,180
  • 2
  • 13
  • 21
1

If you have both python2.X and python3.X installed than you can use sudo python3 -m pip install python-dateutil

Polish
  • 554
  • 1
  • 4
  • 18