运行celeryd时,为什么会出现“SyntaxError:非ASCII字符'\ xa3'”?

时间:2012-01-13 21:07:44

标签: python django ubuntu virtualenv celery

我正在尝试使用Django& amp; Ubuntu上的Virtualenv和我收到此错误:

celeryd-multi v2.4.5
> Starting nodes...
    > celery.heron:   File "/sites/.virtualenvs/myproject/bin/python", line 1
SyntaxError: Non-ASCII character '\xa3' in file /sites/.virtualenvs/myproject/bin/python on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
* Child terminated with failure code 1
FAILED

我认为这是编码问题,但不确定在哪里。我将# -*- coding: utf-8 -*-添加到我的celeryd-multi脚本,以及我的manage.py脚本,以及包含任务代码的实际.py文件中,但是没有解决它。

这是我的/etc/default/celeryd配置文件:

CELERYD="/sites/.virtualenvs/myproject/bin/python /sites/dev.myproject.co/code/myproject/manage.py celeryd"

CELERYD_CHDIR="/sites/dev.myproject.co/code/myproject"

DJANGO_SETTINGS_MODULE="settings"

CELERYD_OPTS="-v 2 -B -s celery -E"

CELERYD_LOG_FILE="/sites/dev.myproject.co/logs/celery.log"

CELERYD_USER="www-data"

CELERYD_GROUP="www-data"

我错过了什么?

2 个答案:

答案 0 :(得分:2)

这不是编码问题。看看哪个文件有编码问题:

  

/sites/.virtualenvs/myproject/bin/python

看起来芹菜试图将你的CELERYD变量解析为python文件,尽管它实际上是python二进制文件。尝试从CELERYD变量声明的开头删除python二进制字符串。

答案 1 :(得分:1)

感谢@gravitron和@ Wooble的提示,我通过在celeryd配置中添加以下内容来解决这个问题:

# Python interpreter from environment.
ENV_PYTHON="/sites/.virtualenvs/myproject/bin/python"

# How to call "manage.py celeryd_multi"
CELERYD_MULTI="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"

# How to call "manage.py celeryctl"
CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"