问题
I am trying to follow the example in the "First Steps with Celery" document. I have installed Celery using pip.
I created a file called tasks.py in ~/python/celery, and it contains the following:
from celery import Celery
celery = Celery('tasks', broker='amqp://guest@localhost//')
@celery.task
def add(x, y):
return x + y
I started a worker using celery -A tasks worker --loglevel=info while in the ~/python/celery directory, and it seems to be running.
In a separate Terminal window, I launched Python and ran the following:
from tasks import add
add.delay(4, 4)
I get the error: File "/Library/Python/2.7/site-packages/celery/utils/timeutils.py", line 17, in from dateutil import tz ImportError: No module named dateutil
How do I install dateutils? It is listed as an installed module when I type "pip freeze"
Thanks!
回答1:
That's strange, since you say you can see it as installed with pip
.
I've just run pip freeze | grep date
and here's what I get:
python-dateutil==1.5
Is your response something similar? Having run the following:
$ python
>>> import dateutil
>>> help(dateutil)
I am told that my dateutil
module is installed in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/__init__.py
(OS X). I would check your Python install to make sure nothing went wrong. There shouldn't be a need to install it separately, but you could perhaps use pip to uninstall then reinstall
回答2:
Had the same issue with Python3, even though when I tried installing it, a message said it already was. So the fix was:
sudo pip3 uninstall python-dateutil
sudo pip3 install python-dateutil
As suggested here.
来源:https://stackoverflow.com/questions/16675463/importerror-no-module-named-dateutil