gpt4 book ai didi

python - Flask - WSGI - 没有名为 'flask' 的模块

转载 作者:太空狗 更新时间:2023-10-29 20:57:57 25 4
gpt4 key购买 nike

我一直在关注 Sentdex 的 Flask 教程。他正在使用 Venv 来设置他的 Flask,但没有将他的 Python 设置为与 Venv 一起工作。我已经尝试在全局范围内安装 Flask - 但它仍然无法正常工作。尝试浏览到服务器返回 500 内部服务器错误

我遇到了常见的no module named flask错误。

errorFGL.log

[Sun Feb 05 11:22:32.043925 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] mod_wsgi (pid=26340): Target WSGI script '/var/www-fgl/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
[Sun Feb 05 11:22:32.044105 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] mod_wsgi (pid=26340): Exception occurred processing WSGI script '/var/www-fgl/FlaskApp/flaskapp.wsgi'.
[Sun Feb 05 11:22:32.044243 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] Traceback (most recent call last):
[Sun Feb 05 11:22:32.045011 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] File "/var/www-fgl/FlaskApp/flaskapp.wsgi", line 8, in <module>
[Sun Feb 05 11:22:32.045070 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] from FlaskApp import app as application
[Sun Feb 05 11:22:32.045549 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] File "/var/www-fgl/FlaskApp/FlaskApp/__init__.py", line 1, in <module>
[Sun Feb 05 11:22:32.045594 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] from flask import Flask
[Sun Feb 05 11:22:32.045689 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] ImportError: No module named 'flask'

__init__.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def homepage():
return "Success"

if __name__ == "__main__":
app.run()

flaskapp.wsgi

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)

sys.path.insert(0,"/var/www-fgl/FlaskApp/")

from FlaskApp import app as application
application.secret_key = '[REDACTED]'

fgl-database.conf

<VirtualHost *:80>
ServerName [REDACTED]
WSGIScriptAlias / /var/www-fgl/FlaskApp/flaskapp.wsgi
<Directory /var/www-fgl>
Require all granted
</Directory>
Alias /static /var/www-fgl/FlaskApp/FlaskApp/static
<Directory /var/www-fgl/FlaskApp/FlaskApp/static/>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/errorFGL.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/accessFGL.log combined




</VirtualHost>

最佳答案

我浪费了大约 25 分钟的时间来寻找解决方案,并且在遵循了我能找到的所有其他资源之后,我还执行了以下操作:

sudo apt-get install libapache2-mod-wsgi-py3

确保在 libapache2-mod-wsgi-py3 的末尾有 '-py3' 否则运行时将默认为 Python2.7

来源:https://vishnut.me/blog/ec2-flask-apache-setup.html

关于python - Flask - WSGI - 没有名为 'flask' 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42050982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com