简体   繁体   English

Celery Supervisor Virtualenv找不到通过github安装的pip软件包

[英]Celery Supervisor Virtualenv can't find pip packages installed via github

Hello I am using supervisor with celery in order to run some tasks in a django web application. 您好,我将芹菜与主管配合使用,以便在Django Web应用程序中运行某些任务。 Celery seems to be having an issue finding/resolving, models from packages that have been installed directly via github. Celery在通过github直接安装的软件包中的模型中查找/解决问题似乎存在问题。

http://pip.readthedocs.org/en/stable/reference/pip_install/#vcs-support http://pip.readthedocs.org/en/stable/reference/pip_install/#vcs-support

As that states the packages are installed/cloned into a <virtualenv>/src directory. 这样一来,软件包就安装/克隆到<virtualenv>/src目录中。 I am wondering if I am missing something in my environment setup with supervisord.conf file such as the PYTHONPATH or something else to have these installed packages available. 我想知道我的环境设置中是否缺少带有supervisord.conf文件的东西,例如PYTHONPATH或其他东西,以使这些安装的软件包可用。 I am getting a 我正在

ValueError: Related model cannot be resolved ValueError:无法解析相关模型

which does not seem to make sense as the application as a whole is working fine with these packages. 这似乎没有任何意义,因为整个应用程序在这些软件包中都可以正常工作。

Versions 版本

Celery - 3.1.18 芹菜-3.1.18

Supervisor - 3.0b2 主管-3.0b2

supervisord.conf supervisord.conf

[program:celeryd]
command=/home/path/to/virtualenv/celery worker -A moi --loglevel=info
stdout_logfile=/var/log/celery/celeryd.log
stderr_logfile=/var/log/celery/celeryd.error.log
directory=/path/to/app

The virtualenv looks structure looks like this virtualenv外观结构如下所示

virtualenv/
  - bin/
  - lib/
  - share/
  - src/github-installed-egg

Error 错误

File "/home/ubuntu/moi/lib/python3.4/site-packages/django/db/models/fields/related.py", line 1600, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.rel.to)
ValueError: Related model 'ndptc_core_courses.Course' cannot be resolved

The web application is running using nginx and uwsgi, and works fine . 该Web应用程序正在使用nginx和uwsgi运行,并且工作正常。 The virtualenv setting in the uwsgi configuration file makes this work. uwsgi配置文件中的virtualenv设置使此工作有效。 The model is a foreign key that is declared by name and not the model object itself. 模型是由名称而不是模型对象本身声明的外键。 Models that are from packages installed via pypi work fine as well its just those installed in the src folder that are causing the issue. 通过pypi安装的程序包中的模型以及导致问题的src文件夹中的模型都可以正常工作。

described in django docs here 在django文档中描述过

Not sure if this is your problem, but a common scenario is to have your app installed under a virtualenv and supervisor installed directly on the host. 不确定这是否是您的问题,但常见的情况是将您的应用安装在virtualenv下,而supervisor直接安装在主机上。

Under this scenario, you need to make sure that the celery version your are running is the one installed in your virtualenv and not a version that might be installed in the host's root environment. 在这种情况下,您需要确保正在运行的celery版本是在virtualenv中安装的版本,而不是主机根环境中可能安装的版本。

As an example, lets assume your virtualenv is located at /opt/virtualenvs/foo and your supervisor program is configured at /etc/supervisor.d/foo.conf . 例如,假设您的virtualenv位于/opt/virtualenvs/foo而主管程序则位于/etc/supervisor.d/foo.conf

[program:foo]
command=/opt/virtualenvs/foo/bin/celery -A celery.conf worker
...

You must "activate" virtualenv in supervisor config. 你必须“激活”中的virtualenv supervisor配置。 To do this, add following line to Your app config: 为此,请将以下行添加到您的应用程序配置中:

environment=PATH="/opt/virtualenvs/foo/bin",VIRTUAL_ENV="/opt/virtualenvs/foo",PYTHONPATH="/opt/virtualenvs/foo/lib/python:/opt/virtualenvs/foo/lib/python/site-packages"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM