无法在Apache上启动Flask应用-找不到flask模块

时间:2019-02-06 09:41:20

标签: python apache amazon-web-services mod-wsgi

使用mod_wsgi在Apache上(在AWS EC2上)部署Flask应用程序时遇到问题。我启用了venv并在其中安装了flask,但是当我尝试获取选定的URL时-我得到了(从apache error.log ):

    Exception occurred processing WSGI script '/var/www/crimemap/crimemap.wsgi'.
    Traceback (most recent call last):
    File "/var/www/crimemap/crimemap.wsgi", line 8, in <module>
    from app import app as application
    File "/var/www/crimemap/app.py", line 1, in <module>
    from flask import Flask, render_template, request
    ImportError: No module named flask

这是crimemap.wsgi文件:

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

from app import app as application
application.secret_key = 'secret key'

我的app.py文件:

from flask import Flask, render_template, request
from dbhelper import DBHelper  
app = Flask(__name__)
DB = DBHelper()

@app.route("/")
def home():
    # do something
    return render_template("index.html", data=data)

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000, debug=True)

还有我的crimemap.conf

<VirtualHost *:80>
        ServerName my_server_name
        WSGIScriptAlias / /var/www/crimemap/crimemap.wsgi
        <Directory /var/www/crimemap/>
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel info
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

好像请求已发送到我的应用程序,但不知何故看不到当前的虚拟环境或其他内容。当我运行python app.py时-我的应用程序正常工作。可能是什么问题?

0 个答案:

没有答案