JackalopeZero JackalopeZero - 1 year ago 172
Python Question

Python cannot find dateutil.relativedelta

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
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:



So this post is now quite a few months old and it just earned me the Popular Question badge, I thought it might be worth taking a look and seeing if I could give a good answer to this question with a bit more experience backing me up.

Immediately I look at this and see that
is only installed for python2.7 and I bet what I was doing was this:

sudo yum install python-dateutil

To which
would have switch to the default Python version (i.e. Python2.7 instead of 2.6.4)

Solving this would have been as simple as:

(switch to virtual environment)
yum install python-dateutil

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

Jon Jon
Answer Source

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.