简体   繁体   English

Python:烧瓶导入失败

[英]Python: Flask import failing

I'm trying to deploy a Flask app on Apache using mod_wsgi.我正在尝试使用 mod_wsgi 在 Apache 上部署 Flask 应用程序。 Im using a virtual environment.我使用的是虚拟环境。 But the below line is failing.但下面的行失败了。

from flask import Flask

Error:错误:

[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

As you can see the error is within the code of flask itself.正如您所看到的,错误在 Flask 本身的代码中。 I'm using Python-3.6.2 which is supported by flask.我正在使用 Flask 支持的 Python-3.6.2。 The source code of flask in which it's showing error is also correct.显示错误的烧瓶源代码也是正确的。 What could be the issue ?可能是什么问题 ?

Sorry for posting this rather then commenting:很抱歉发布这个而不是评论:

Try to install Flask 1.1.1 which worked for me:尝试安装对我有用的 Flask 1.1.1:

pip install Flask==1.1.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM