芹菜导入错误

时间:2014-01-22 11:26:58

标签: python django celery

我在开始芹菜时遇到导入错误。这很令人困惑,因为这在几天前就已经开始了,git显示没有任何改变。我认为celery对导入目录的启发式方法与我的拆分设置结构相冲突,也许我的路径/ env与invokation工作时的路径/ env不同?我应该如何调整我的invokation或环境来帮助celery加载所有下游导入?这是Celery 3.1.7和Django 1.6。

我的邀请:

celery worker --app=proj.proj

错误:

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

我的项目如下:

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

我的env vars是:

DJANGO_SETTINGS_MODULE=proj.settings.local
DJANGO_PROJECT_DIR=/home/ben/Projects/proj/proj/proj
编辑:我正在使用virtualenv,所以启动时我的$ PATH看起来像

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

2 个答案:

答案 0 :(得分:1)

我的virtualenv以某种方式被腐蚀了。一个新的virtualenv具有相同的env vars和已安装的软件。

答案 1 :(得分:0)

你芹菜使用错误的工作目录,因此无法找到相对路径proj.settings.local

尝试将您的设置修改为DJANGO_PROJECT_DIR=/home/ben/Projects/proj/proj并查看其是否有效。