gpt4 book ai didi

python - 为 python Web 应用程序运行 apache 服务器时导入错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:01:31 25 4
gpt4 key购买 nike

我正在 linux 服务器配置上做我的项目,并在 amazon lighsail 上使用 ubuntu。我安装了 python2.7.5 和 python 3 我通过更改别名将其更改为 python 3,因为我的应用程序在 python3 上。

我的wsgi服务器配置如下

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")

from FlaskApp import app as application
application.secret_key = 'Add your secret key'

我的配置文件如下

<VirtualHost *:80>
ServerName 52.24.125.53
ServerAdmin abc@gmail.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

当我尝试通过 ip 地址访问时,它显示内部错误 500

错误日志如下

[Mon Sep 10 15:53:22.843424 2018] [wsgi:error] [pid 3620:tid 140263087400704] [client 103.211.114.174:27167]     from flask import Flask, render_template
[Mon Sep 10 15:53:22.843450 2018] [wsgi:error] [pid 3620:tid 140263087400704] [client 103.211.114.174:27167] ImportError: No module named 'flask'
[Mon Sep 10 15:53:23.421818 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] mod_wsgi (pid=3619): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://18.222.248.66/
[Mon Sep 10 15:53:23.421875 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] mod_wsgi (pid=3619): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://18.222.248.66/
[Mon Sep 10 15:53:23.421968 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] Traceback (most recent call last):, referer: http://18.222.248.66/
[Mon Sep 10 15:53:23.421991 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://18.222.248.66/
[Mon Sep 10 15:53:23.421995 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] from FlaskApp import app as application, referer: http://18.222.248.66/
[Mon Sep 10 15:53:23.422001 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 1, in <module>, referer: http://18.222.248.66/
[Mon Sep 10 15:53:23.422004 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] from flask import Flask, render_template, referer: http://18.222.248.66/
[Mon Sep 10 15:53:23.422019 2018] [wsgi:error] [pid 3619:tid 140263194842880] [client 103.211.114.174:27174] ImportError: No module named 'flask', referer: http://18.222.248.66/

我已经在 python3 和 python2.7.5 包上安装了所有模块。但仍然显示导入错误。我认为它与 wsgi 有问题。我是新手,请帮助解决问题。

最佳答案

您需要检查应用中的模块名称

我认为您导入了模块名称“from flask import flask”。

(或)

你需要安装flask

pip install Flask

关于python - 为 python Web 应用程序运行 apache 服务器时导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52256121/

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