Python cannot find dateutil.relativedelta

RonnyKnoxville picture RonnyKnoxville · Dec 7, 2011 · Viewed 61.2k times · Source

I am trying to run a program using paster serve, but I keep getting the error:

ImportError: No module named dateutil.relativedelta

I am running Python version 2.6.7 and dateutil version 1.5, so it should be installed.

Has anyone got any ideas as to why this would happen?

I am importing using

from dateutil.relativedelta import *

I can even see the package when I search:

/usr/lib/python2.7/site-packages/dateutil/relativedelta.pyc
/usr/lib/python2.7/site-packages/dateutil/relativedelta.py
/usr/lib/python2.7/site-packages/dateutil/relativedelta.pyo

UPDATE

Immediately I look at this and see that dateutil is only installed for Python 2.7, and I bet what I was doing was this:

sudo yum install python-dateutil

To which sudo would have switch to the default Python version (i.e., Python 2.7 instead of 2.6.4).

Solving this would have been as simple as:

su
(switch to virtual environment)
yum install python-dateutil

Using su and then switching to the virtual environment will give root access and install to the virtual Python directory. Using sudo will install libraries to the default directory, not the virtual environments site-packages.

Answer

Jon picture Jon · Oct 14, 2012

I also ran into this issue. The simple solution I ended up using was to add --upgrade to the end of the command. This forced it to install it even though Python thought it was installed. This resolved the issue.

So if you have this issue, try the following:

sudo pip install python-dateutil --upgrade

It can't possibly hurt anything, so there is no harm in just forcing it to be reinstalled.