守护芹菜-没有名为“芹菜”的模块错误

问题描述 投票:1回答:1

[official documentation之后,我试图在Ubuntu 18上守护Celery 4.3.0。这是为了让Django项目减轻繁重的任务。

当服务器运行celery.service时,应使Celery worker可用于处理任务。但是,Apache2甚至无法运行。如果我tail Apache日志,我看到:

[Sun Sep 29 07:42:07.621273 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Sun Sep 29 07:42:07.621279 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
[Sun Sep 29 07:42:07.621285 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
[Sun Sep 29 07:42:07.621291 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
[Sun Sep 29 07:42:07.621297 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Sun Sep 29 07:42:07.621303 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "/var/www/html/examgap/examgap/__init__.py", line 5, in <module>
[Sun Sep 29 07:42:07.621307 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]     from .celery import app as celery_app
[Sun Sep 29 07:42:07.621313 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "/var/www/html/examgap/examgap/celery.py", line 5, in <module>
[Sun Sep 29 07:42:07.621317 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]     from celery import Celery
[Sun Sep 29 07:42:07.621333 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952] ModuleNotFoundError: No module named 'celery'

Celery绝对是为Python3安装的。我可以使用celery -A examgap worker -l warning独立运行我的应用程序的Celery worker,而不能作为守护程序运行。

如果启动Python3 Shell,我也可以导入celery。

我看了几个现有的SO问题,例如this one,并认为我消除了一些可能性。例如,守护程序用户是ubuntu,它对我的​​项目文件夹具有rwx权限。

我仍然认为问题出在我的celery.service文件和启动守护程序的命令不访问正确的文件夹或使用正确的权限。

这里是我的/etc/systemd/system/celery.service

[Unit]
Description=Celery Service
After=network.target

[Service]
Type=forking
User=ubuntu
Group=ubuntu
EnvironmentFile=/etc/conf.d/celery
WorkingDirectory=/opt/celery
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE}' ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

[Install]
WantedBy=multi-user.target

提前感谢。

编辑:这也是我的/etc/conf.d/celery

# Name of nodes to start
# here we have a single node
CELERYD_NODES="eg1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"

# Absolute or relative path to the 'celery' command:
#CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"
#Think I installed Celery only for user ubuntu
CELERY_BIN="/home/ubuntu/.local/bin/celery"

#CELERYD_CHDIR="/var/www/html/examgap/"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="examgap"
# or fully qualified:
# CELERY_APP="examgap.tasks:app"

# How to call manage.py
CELERYD_MULTI="multi"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"

# - %n will be replaced with the first part of the nodename.
# - %I will be replaced with the current child process index
#   and is important when using the prefork pool to avoid race conditions.
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_LOG_LEVEL="INFO"

编辑2:将WorkingDirectory更改为我的项目目录,现在celery服务正在运行。但是ModuleNotFoundError: No module named 'celery'仍然存在。

django celery django-celery celeryd daemons
1个回答
0
投票
[Sun Sep 29 07:42:07.621313 2019] [wsgi:error] [pid 2648:tid 140134825535232] [remote 92.4.204.209:55952]   File "/var/www/html/examgap/examgap/celery.py", line 5, in <module>

似乎您有自己的celery.py,如果这样,您应该对其进行重命名以避免导入问题

© www.soinside.com 2019 - 2024. All rights reserved.