本文介绍了Flask-WSGI-没有名为"flask"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注Sentdex的Flask教程.他使用Venv来设置他的Flask,但是没有设置Python与Venv一起使用.我曾尝试在全球范围内安装Flask-但仍然无法正常工作.尝试浏览到服务器会返回500 Internal Server Error

I've been following Sentdex' Flask tutorial. He's using a Venv to set up his Flask, but didn't set his Python up to work with a Venv. I've tried installing Flask globally - yet it still doesn't work. Trying to browse to the server returns a 500 Internal Server Error

我遇到了常见的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>

推荐答案

就像在查找解决方案时的礼貌举止一样,我在Google上搜索了更多内容,并设法从Nathan Nichols的YouTube评论中找到了解决方案:

As is polite behaviour when finding the solution, I googled around a bit more, and somehow managed to find a solution from a YouTube commment by Nathan Nichols here:

  1. 编辑/etc/apache2/sites-available/FlaskApp.conf
  2. 在"WSGIScriptAlias"行之前添加以下两行:

  1. Edit /etc/apache2/sites-available/FlaskApp.conf
  2. Add the following two lines before the "WSGIScriptAlias" line:

WSGIDaemonProcess FlaskApp python-path=/var/www/FlaskApp:/var/www/FlaskApp/FlaskApp/venv/lib/python2.7/site-packages
WSGIProcessGroup FlaskApp

  • 通过"service apache2 restart"重新启动Apache
  • 我当然用我正在运行的python3.5替换了Python版本.

    I of course replaced the Python version with python3.5, which is what I'm running.

    这篇关于Flask-WSGI-没有名为"flask"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-14 17:16