Celery import error
Question: I am hitting an import error in starting celery. This is confusing, because
this was working a few days ago, and git shows nothing changed. I think
celery's heuristics for import directories are colliding with my split-out
setting structure, and maybe my path/env is different than it was when the
invokation was working? How should I tweak my invokation or environment to
help celery load all of its downstream imports? This is Celery 3.1.7 and
Django 1.6.

My invokation:

    
    
    celery worker --app=proj.proj
    

The error:

    
    
    Traceback (most recent call last):
      File "/home/ben/.virtualenvs/proj/bin/celery", line 8, in <module>
        load_entry_point('celery==3.1.7', 'console_scripts', 'celery')()
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/__main__.py", line 30, in main
        main()
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/celery.py", line 80, in main
        cmd.execute_from_commandline(argv)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/celery.py", line 723, in execute_from_commandline
        super(CeleryCommand, self).execute_from_commandline(argv)))
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/base.py", line 303, in execute_from_commandline
        return self.handle_argv(self.prog_name, argv[1:])
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/celery.py", line 715, in handle_argv
        return self.execute(command, argv)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/celery.py", line 669, in execute
        ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/worker.py", line 175, in run_from_argv
        return self(*args, **options)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/base.py", line 266, in __call__
        ret = self.run(*args, **kwargs)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/bin/worker.py", line 208, in run
        state_db=self.node_format(state_db, hostname), **kwargs
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/worker/__init__.py", line 95, in __init__
        self.app.loader.init_worker()
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/loaders/base.py", line 128, in init_worker
        self.import_default_modules()
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/loaders/base.py", line 121, in import_default_modules
        tuple(maybe_list(self.app.conf.CELERY_INCLUDE))
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/loaders/base.py", line 103, in import_task_module
        return self.import_from_cwd(module)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/loaders/base.py", line 112, in import_from_cwd
        package=package,
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
        return imp(module, package=package)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/celery/loaders/base.py", line 106, in import_module
        return importlib.import_module(module, package=package)
      File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "/home/ben/Projects/proj/proj/proj/matches/management/tasks/valve_api_calls.py", line 9, in <module>
        from matches.models import Match, LobbyType, GameMode,\
      File "/home/ben/Projects/proj/proj/proj/matches/models.py", line 1, in <module>
        from django.db import models
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
        if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
        self._setup(name)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
        self._wrapped = Settings(settings_module)
      File "/home/ben/.virtualenvs/proj/local/lib/python2.7/site-packages/django/conf/__init__.py", line 134, in __init__
        raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
    ImportError: Could not import settings 'proj.settings.local' (Is it on sys.path?): No module named settings.local
    

My project looks like:

    
    
    proj <git root>
    └──proj <project root>
       └── manage.py
       └── proj <project app>
           └── celery_app.py
           └── settings
               └── local.py
    

My env vars are:

    
    
    DJANGO_SETTINGS_MODULE=proj.settings.local
    DJANGO_PROJECT_DIR=/home/ben/Projects/proj/proj/proj
    

EDIT: I am using virtualenv, so my $PATH on startup looks like

    
    
    PATH=/home/ben/.virtualenvs/proj/bin:
    /usr/local/heroku/bin:/usr/lib/lightdm/lightdm:
    /usr/local/sbin:/usr/local/bin:
    /usr/sbin:
    /usr/bin:
    /sbin:
    /bin:
    /usr/games:
    /usr/local/games
    


Answer: My virtualenv got corrupted somehow. A new virtualenv with identical env vars
and installed software works.

