首页 > 解决方案 > Python:烧瓶导入失败

问题描述

我正在尝试使用 mod_wsgi 在 Apache 上部署 Flask 应用程序。我使用的是虚拟环境。但是下面的行失败了。

from flask import Flask

错误:

[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] mod_wsgi (pid=6937): Target WSGI script '/var/www/sample_rest/sample_rest.wsgi' cannot be loaded as Python module.
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] mod_wsgi (pid=6937): Exception occurred processing WSGI script '/var/www/sample_rest/sample_rest.wsgi'.
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] Traceback (most recent call last):
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]   File "/var/www/sample_rest/sample_rest.wsgi", line 5, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]  from sample_rest import sample_rest as application
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]   File "/var/www/sample_rest/sample_rest.py", line 2, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]     from flask import Flask, request, jsonify, make_response
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]   File "/var/www/sample_rest/lib/python3.6/site-packages/flask/__init__.py", line 16, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]     from werkzeug.exceptions import abort
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]   File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/__init__.py", line 15, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]     from .serving import run_simple
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]   File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/serving.py", line 51, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]     from .exceptions import InternalServerError
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]   File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/exceptions.py", line 68, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]     from .utils import escape
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]   File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/utils.py", line 189
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]     "area",
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]      ^ 
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242]  SyntaxError: invalid syntax

如您所见,错误在烧瓶本身的代码中。我正在使用烧瓶支持的 Python-3.6.2。显示错误的烧瓶的源代码也是正确的。可能是什么问题 ?

标签: pythonpython-3.xapacheflaskmod-wsgi

解决方案


很抱歉发布此内容而不是评论:

尝试安装对我有用的 Flask 1.1.1:

pip install Flask==1.1.1

推荐阅读