Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 728
RonnyKnoxville Avatar asked Dec 07 '11 16:12

RonnyKnoxville


People also ask

What is Dateutil Relativedelta Python?

The relativedelta type is designed to be applied to an existing datetime and can replace specific components of that datetime, or represents an interval of time. It is based on the specification of the excellent work done by M. -A. Lemburg in his mx. DateTime extension.


1 Answers

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.

like image 101
Jon Avatar answered Oct 02 '22 13:10

Jon