我有一个基本的烧瓶应用程序,我正在创建该应用程序来定期发送电子邮件。当我安装芹菜时,我在一个名为more_itertools
的库中收到语法错误,它所依赖。
...
[838946] yield from iterable
[838950] ^
[838955] SyntaxError: invalid syntax
我无法进一步排除故障。请帮忙。
- 芹菜版本 - 4.3.0
- 蟒蛇版本 - 3.6.8
要求.txt:
alembic==1.3.1
amqp==2.5.2
billiard==3.6.1.0
blinker==1.4
celery==4.3.0
certifi==2019.6.16
chardet==3.0.4
Click==7.0
colorama==0.4.1
Flask==1.1.1
Flask-Mail==0.9.1
Flask-Migrate==2.5.2
Flask-SQLAlchemy==2.4.1
idna==2.8
importlib-metadata==1.3.0
itsdangerous==1.1.0
Jinja2==2.10.1
kombu==4.6.7
Mako==1.1.0
MarkupSafe==1.1.1
more-itertools==8.0.2
pymaging==0.1
pymaging-png==0.1
python-dateutil==2.8.1
python-editor==1.0.4
pytz==2019.3
qrcode==6.1
razorpay==1.2.0
requests==2.22.0
six==1.12.0
SQLAlchemy==1.3.11
urllib3==1.25.3
vine==1.3.0
Werkzeug==0.15.5
zipp==0.6.0
__init__.py
...
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
...
视图/首页.py
...
r = send_mail(email).delay(10, 20)
...
@celery.task
def send_mail(email):
# email stuff
完整回溯:
[838493] mod_wsgi (pid=12557): Exception occurred processing WSGI script '/var/www/myapp.com/public_html/myapp.wsgi'.
[838556] Traceback (most recent call last):
[838580] File "/var/www/myapp.com/public_html/myapp.wsgi", line 4, in <module>
[838617] from myapp import app as application
[838626] File "/var/www/myapp.com/public_html/myapp/__init__.py", line 13, in <module>
[838642] from celery import Celery
[838650] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/celery/local.py", line 509, in __getattr__
[838665] module = __import__(self._object_origins[name], None, None, [name])
[838672] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/celery/app/__init__.py", line 5, in <module>
[838686] from celery import _state
[838693] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/celery/_state.py", line 17, in <module>
[838705] from celery.utils.threads import LocalStack
[838712] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/celery/utils/__init__.py", line 8, in <module>
[838726] from .functional import memoize # noqa
[838745] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/celery/utils/functional.py", line 10, in <module>
[838759] from kombu.utils.functional import (LRUCache, dictfilter, is_list, lazy,
[838766] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/kombu/utils/__init__.py", line 5, in <module>
[838779] from .compat import fileno, maybe_fileno, nested, register_after_fork
[838786] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/kombu/utils/compat.py", line 14, in <module>
[838798] import importlib_metadata
[838805] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 9, in <module>
[838818] import zipp
[838825] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/zipp.py", line 12, in <module>
[838844] import more_itertools
[838868] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/more_itertools/__init__.py", line 1, in <module>
[838893] from .more import * # noqa
[838939] File "/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/more_itertools/more.py", line 460
[838946] yield from iterable
[838950] ^
[838955] SyntaxError: invalid syntax
阿帕奇配置:
<VirtualHost *:80>
ServerAdmin admin@myapp.com
ServerName myapp.com
WSGIDaemonProcess myapp user=myuser group=sudo threads=5 python-path=/var/www/myapp.com:/var/www/myapp.com/public_html/venv/lib/python3.6/site-packages/
WSGIScriptAlias / /var/www/myapp.com/public_html/myapp.wsgi
DocumentRoot /var/www/myapp.com/public_html
<Directory /var/www/myapp.com/public_html>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
WSGIScriptReloading On
</Directory>
</VirtualHost>
myapp.wsgi
import sys
sys.path.insert(0, "/var/www/myapp.com/public_html/")
from myapp import app as application
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(application, True)
1. 尝试添加
python-home=directory
设置守护进程要使用的 Python 虚拟环境的位置。要使用的目录是为 Python 虚拟环境设置 sys.prefix 的目录。虚拟环境可以由virtualenv,pyvenv或python -m venv创建。
请注意,Python 虚拟环境必须是使用与编译 mod_wsgi 模块相同的基本 Python 版本创建的。你不能用它来强迫mod_wsgi以某种方式使用与编译时不同的 Python 版本。如果你想使用不同版本的Python,你需要重新安装mod_wsgi,将其编译为你想要的版本。一个mod_wsgi实例不可能同时运行 Python 2 和 3 的应用程序。
来自 modwsgi 文档 https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html#wsgidaemonprocess
2. 打印当前"Apache 运行 python 版本">
将print(sys.version)
添加到您的myapp.wsgi
脚本中,以便在 apache 日志 python 运行版本中查看
我不认为你真的在运行Python3.6。python解释器实际上是mod_wsgi选择的,并且可能是一个较旧的解释器,还不支持yield from
-Syntax。
有关如何验证实际选择的口译员的说明,请参阅 https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-installation-in-use。
我也遇到了这个问题,我正在研究 python2.7 环境。 根本原因是因为芹菜对海带有依赖,
尝试使用pip freeze | grep kombu
来检查您的昆布版本
我看到我的版本是4.6.0, 我删除了 4.6.0 并降级到 4.1.0
解决了这个问题