import error in celeryd task
Question: I am having problems running my celery task because it cannot find one of my
modules:

    
    
    (ff)bash-3.2$ flipfinder_app/manage.py celeryd
    [...]
    Traceback (most recent call last):
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/billiard/process.py", line 248, in _bootstrap
    self.run()
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/billiard/process.py", line 97, in run
    self._target(*self._args, **self._kwargs)
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/billiard/pool.py", line 268, in worker
    initializer(*initargs)
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/concurrency/processes/__init__.py", line 51, in process_initializer
    app.loader.init_worker()
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 115, in init_worker
    self.import_default_modules()
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/djcelery/loaders.py", line 136, in import_default_modules
    super(DjangoLoader, self).import_default_modules()
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 110, in import_default_modules
    | self.builtin_modules]
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 96, in import_task_module
    return self.import_from_cwd(module)
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 104, in import_from_cwd
    package=package)
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/utils/imports.py", line 96, in import_from_cwd
    return imp(module, package=package)
    File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 99, in import_module
    return importlib.import_module(module, package=package)
    File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
    File "/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps/tabs/keywords/tasks.py", line 11, in <module>
    from apps.util.adsense import has_adsense
    ImportError: No module named adsense
    

It does exist:

    
    
    (ff)bash-3.2$ pwd
    /Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps/util
    (ff)bash-3.2$ ls | grep adsense
    adsense.py
    

And when I use the django shell, it imports fine.

    
    
    (ff)bash-3.2$ ff_app/manage.py shell
    Python 2.7.3 (default, Jan  9 2013, 09:25:40) 
    [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.65))] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>> from apps.util.adsense import has_adsense
    >>> has_adsense
    <function has_adsense at 0x10d3171b8>
    

I added this to the task file:

    
    
    import sys
    print sys.path
    

and see this output when I try to run celery:

    
    
    ['/Users/jasonlfunk/Workspace/Work/csm/ff-app', '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/lib',
     '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps', '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/lib',
     '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps', '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
     '/Users/jasonlfunk/.virtualenvs/ff/src/pywhois', '/Users/jasonlfunk/.virtualenvs/ff/src/django-filter',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python27.zip', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/plat-darwin', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/plat-mac',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/lib-tk',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/lib-old', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/lib-dynload',
     '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
     '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
     '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
     '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
     '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/PIL',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/newrelic-1.5.0.103',
     '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
    

You can see that `/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app` is in
the path which is where the import should be.

I aslo added this to the tasks file:

    
    
    import os
    os.chdir('/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app')
    

And everything works fine.

    
    
     -------------- celery@Jason-Funks-MacBook-Pro.local v3.0.11 (Chiastic Slide)
    ---- **** ----- 
    --- * ***  * -- [Configuration]
    -- * - **** --- . broker:      django://guest@localhost:5672//
    - ** ---------- . app:         default:0x10ddf5810 (djcelery.loaders.DjangoLoader)
    - ** ---------- . concurrency: 2 (processes)
    - ** ---------- . events:      OFF (enable -E to monitor this worker)
    - ** ---------- 
    - *** --- * --- [Queues]
    -- ******* ---- . celery:      exchange:celery(direct) binding:celery
    --- ***** ----- 
    
    [2013-01-16 17:22:53,248: WARNING/MainProcess] celery@Jason-Funks-MacBook-Pro.local ready.
    

What's going on? Why does cd'ing into a directory that is already in my path
fix the problem? Any ideas?


Answer: Is **from apps.util.adsense import has_adsense** inside task def ?

