我使用Ubuntu Server 18.04,Django,我想在系统中使用芹菜。
我有以下错误:
ModuleNotFoundError: No module named 'ph'
May 02 21:02:55 ph-1c1m1t sh[2646]: Traceback (most recent call last):
我知道这是一个路径错误,但我尝试了多个关于app的组合,我无法解决它。
项目结构是:
username
-projects
-src
- ph
- settings (folder)
- celery.py
-urls.py
配置文件
CELERYD_NODES="w1 w2"
CELERY_BIN="/home/username/env/prod/bin/celery"
CELERY_APP="ph.celery:app"
CELERYD_MULTI="multi"
CELERYD_OPTS="--time-limit=300 --concurrency=8"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_LOG_LEVEL="INFO"
在systemd,celery.service我有:
[Unit]
Description=Celery Service
After=network.target
[Service]
Type=forking
User=username
Group=username
WorkingDirectory=/home/username/env/prod/
EnvironmentFile=-/etc/celery/celery.conf
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
答案 0 :(得分:1)
尝试在PYTHONPATH
中指定/etc/celery/celery.conf
。这应该指向包含ph
包的文件夹。
PYTHONPATH=/home/username/projects/src
CELERYD_NODES="w1 w2"
CELERY_BIN="/home/username/env/prod/bin/celery"
CELERY_APP="ph.celery:app"
CELERYD_MULTI="multi"
CELERYD_OPTS="--time-limit=300 --concurrency=8"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_LOG_LEVEL="INFO"