unregistered task type import errors in celery
Question: I'm having headaches with getting celery to work with my folder structure.
Note I am using virtualenv but it should not matter.

    
    
    cive /
        celery_app.py
        __init__.py
        venv
        framework /
            tasks.py
            __init__.py
            civeAPI /
                files tasks.py need
    

cive is my root project folder.

celery_app.py:

    
    
    from __future__ import absolute_import
    
    from celery import Celery
    
    app = Celery('cive',
             broker='amqp://',
             backend='amqp://',
             include=['cive.framework.tasks'])
    
    # Optional configuration, see the application user guide.
    app.conf.update(
        CELERY_TASK_RESULT_EXPIRES=3600,
    )
    
    if __name__ == '__main__':
        app.start()
    

tasks.py (simplified)

    
    
    from __future__ import absolute_import  
    #import other things
    #append syspaths
    from cive.celery_app import app  
    
    @app.task(ignore_result=False)
    def start(X):
        # do things
    
    def output(X):
        # output files
    
    def main():
        for d in Ds:
            m = []
            m.append( start.delay(X) )
            output( [n.get() for n in m] )
    
    if __name__ == '__main__':
        sys.exit(main(sys.argv[1:]))
    

I then start workers via (outside root cive dir)

    
    
    celery -A cive worker --app=cive.celery_app:app -l info
    

which seems to work fine, loading the workers and showing

    
    
    [tasks]
      . cive.framework.tasks.start_sessions
    

But when I try to run my tasks.py via another terminal:

    
    
    python tasks.py
    

I get the error:

    
    
    Traceback (most recent call last):
      File "tasks.py", line 29, in <module>
        from cive.celery_app import app
    ImportError: No module named cive.celery_app
    

If I rename the import to:

    
    
    from celery_app import app #without the cive.celery_app 
    

I can eventually start the script but celery returns error:

    
    
    Received unregistered task of type 'cive.start_sessions'
    

I think there's something wrong with my imports or config but I can't say
what.


Answer: So this was a python package problem, not particularly a celery issue. I found
the solution by looking at [Attempted relative import in non-package even with
__init__.py](http://stackoverflow.com/questions/11536764/attempted-relative-
import-in-non-package-even-with-init-py) .

I've never even thought about this before, but I wasn't running python in
package mode. The solution is cd'ing out of your root project directory, then
running python as a package (note there is no .py after tasks):

    
    
     python -m cive.framework.tasks
    

Now when I run the celery task everything works.

