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

标签 python linux python-3.x apache ubuntu

我正在 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/

相关文章:

Python2 哈希值分布不良

python - 使用列表制作 pandas df

linux - 无法在 Ubuntu 上启动 Visual Studio Code

linux - __gmon_start 在_start 之前执行

python - 如何在具有指定错误概率的图像中添加合成噪声

python - 嵌套词典未按要求更新

python - re.DOTALL 适用于 re.match 但不适用于 re.sub?

python - 在 Python 中创建多语言拼字游戏

c - 第二个 getpwuid 调用似乎覆盖了旧值

python-3.x - 错误: name 'Image' not defined