A workaround is to install a system-wide celery, but this is clearly not desired behavior of fabric.
Running fabric script throws ImportError: No module named celery
Question
I've been tearing my hear out for quite some time now.
- I am in my virtualenv and I have
celery==3.1.9
installed there. - I have a default celery/django setup (http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html) and it is working fine.
As soon as I run any fabric scripts it throws ImportError: No module named celery
originating from my proj/proj/celery.py
file. What is going on?
Full traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/fabric/main.py", line 658, in main
docstring, callables, default = load_fabfile(fabfile)
File "/usr/local/lib/python2.7/dist-packages/fabric/main.py", line 165, in load_fabfile
imported = importer(os.path.splitext(fabfile)[0])
File "/home/username/Projects/proj/fabfile/__init__.py", line 2, in <module>
from .staging import *
File "/home/username/Projects/proj/fabfile/staging.py", line 3, in <module>
from proj.settings.staging import DOMAIN, IP, USER, PASSWORD
File "/home/username/Projects/proj/proj/__init__.py", line 5, in <module>
from .celery import app as celery_app
File "/home/username/Projects/proj/proj/celery.py", line 3, in <module>
from celery import Celery
ImportError: No module named celery
EDIT: I don't think the contents of my fabric scripts have anything to do with it. For the sake of example I set:
from fabric.api import local
def foo():
local('echo bar')
Calling fab foo
raises ImportError: No module named celery
. Actually if I call just fab
the result is the same.
My proj/proj/__init__.py
:
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
Just as in the celery tutorial
EDIT:
This works:
(venv)rg@dfi:~/Projects/proj$ python
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from celery import Celery
>>>
Solution
OTHER TIPS
I stumbled across the same problem. Since I wanted to send a task from fabric rather than registering tasks, I used the celery command line interface instead:
from fabric.api import local
def run_slow_tests():
local("celery call 'myapp.tasks.run_slow_tests'")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow