Python 烧瓶和mod_wsgi导入错误

Python 烧瓶和mod_wsgi导入错误,python,apache,flask,mod-wsgi,Python,Apache,Flask,Mod Wsgi,我正在尝试使用mod_wsgi在Ubuntu 16.04上通过apache安装flask应用程序。现在的情况是wsgi脚本无法导入任何python模块 我已经验证了wsgi脚本是可执行的,并且已经用python独立运行了它。我还验证了我的flask应用程序可以自己运行,没有错误。我能够导入我运行的任何其他python程序中的所有模块。我还安装了带有pip和源代码的烧瓶。似乎什么都没用 这是我的错误日志: [Wed Feb 01 02:00:39.939582 2017] [wsgi:error]

我正在尝试使用mod_wsgi在Ubuntu 16.04上通过apache安装flask应用程序。现在的情况是wsgi脚本无法导入任何python模块

我已经验证了wsgi脚本是可执行的,并且已经用python独立运行了它。我还验证了我的flask应用程序可以自己运行,没有错误。我能够导入我运行的任何其他python程序中的所有模块。我还安装了带有pip和源代码的烧瓶。似乎什么都没用

这是我的错误日志:

[Wed Feb 01 02:00:39.939582 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850] mod_wsgi (pid=6286): Target WSGI script '/var/www/html/flaskapp/flaskapp.wsgi' cannot be loaded as Python module.
[Wed Feb 01 02:00:39.939616 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850] mod_wsgi (pid=6286): Exception occurred processing WSGI script '/var/www/html/flaskapp/flaskapp.wsgi'.
[Wed Feb 01 02:00:39.939633 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850] Traceback (most recent call last):
[Wed Feb 01 02:00:39.939651 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]   File "/var/www/html/flaskapp/flaskapp.wsgi", line 4, in <module>
[Wed Feb 01 02:00:39.939677 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]     from flaskapp import app as application
[Wed Feb 01 02:00:39.939684 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]   File "/var/www/html/flaskapp/flaskapp.py", line 1, in <module>
[Wed Feb 01 02:00:39.939693 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]     from flask import Flask, json, request, jsonify
[Wed Feb 01 02:00:39.939707 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]   File "/usr/local/lib/python2.7/dist-packages/Flask-0.13.dev0-py2.7.egg/flask/__init__.py", line 21, in <module>
[Wed Feb 01 02:00:39.939716 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]     from .app import Flask, Request, Response
[Wed Feb 01 02:00:39.939720 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]   File "/usr/local/lib/python2.7/dist-packages/Flask-0.13.dev0-py2.7.egg/flask/app.py", line 26, in <module>
[Wed Feb 01 02:00:39.939728 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]     from . import json, cli
[Wed Feb 01 02:00:39.939732 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]   File "/usr/local/lib/python2.7/dist-packages/Flask-0.13.dev0-py2.7.egg/flask/cli.py", line 17, in <module>
[Wed Feb 01 02:00:39.939739 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850]     import click
[Wed Feb 01 02:00:39.939755 2017] [wsgi:error] [pid 6286:tid 140540005824256] [client 73.241.170.36:45850] ImportError: No module named click
这是我的烧瓶程序:

from flask import Flask, json, request, jsonify
import numpy as np

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello from Flask!'

if __name__ == '__main__':
    app.run()
/var/www/html/flaskapp
包含
flaskapp.py和flaskapp.wsgi

我遗漏了什么?谢谢

编辑:这是我的
/etc/apache2/sites enabled/000 default.conf

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    WSGIDaemonProcess flaskapp threads=5
    WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi

    <Directory flaskapp>
            WSGIProcessGroup flaskapp
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

#ServerName指令设置请求方案、主机名和端口
#服务器使用来标识自身。这在创建时使用
#重定向URL。在虚拟主机的上下文中,服务器名
#指定必须在请求的主机:标头中显示的主机名
#匹配此虚拟主机。对于默认虚拟主机(此文件),此
#该值不是决定性的,因为它被用作最后的宿主。
#但是,必须为任何其他虚拟主机显式设置它。
#服务器名www.example.com
服务器管理员webmaster@localhost
DocumentRoot/var/www/html
WSGIDaemonProcess烧瓶应用程序线程数=5
WSGIScriptAlias//var/www/html/flaskapp/flaskapp.wsgi
WSGIProcessGroup烧瓶应用程序
WSGIApplicationGroup%{GLOBAL}
命令拒绝,允许
通融
#可用日志级别:trace8、…、trace1、调试、信息、通知、警告、,
#错误、暴击、警报、紧急情况。
#还可以为特定应用程序配置日志级别
#模块,例如。
#日志级别信息ssl:警告
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
#对于conf/available/中的大多数配置文件
#在全局级别启用或禁用,可以
#仅包含一个特定虚拟主机的行。例如
#以下行仅为此主机启用CGI配置
#在使用“A2F”全局禁用后。
#包括conf available/service-cgi-bin.conf
#vim:syntax=apachets=4sw=4sts=4srnoet

我今天正在处理这个问题。如果您使用的是Apache2.4,这是一个简单的更改:

<Directory flaskapp>
        WSGIProcessGroup flaskapp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
</Directory>

WSGIProcessGroup烧瓶应用程序
WSGIApplicationGroup%{GLOBAL}
命令拒绝,允许
通融
致:


WSGIProcessGroup烧瓶应用程序
WSGIApplicationGroup%{GLOBAL}
要求所有授权
更多信息请点击此处:

另外,不确定这是否有区别,但我的目录是apache配置中的完整路径:

    Alias /static /var/www/appname/app/static/
    <Directory /var/www/appname/app/>
            Require all granted
    </Directory>
    <Directory /var/www/appname/app/static/>
            Require all granted
    </Directory>
Alias/static/var/www/appname/app/static/
要求所有授权
要求所有授权

Apache配置文件?通常/etc/apache2/sites enabled/000-default.conf为什么要运行Flask的开发版本?从错误消息看,它似乎缺少一个程序包。我已经编辑了配置文件,我将在稍后发布。我如何运行flask的开发版本?我不认为我丢失了一个包,因为我可以运行
python-flaskapp.py
而不会出现问题。基于错误,我可以尝试
sudo-pip-install-click
。在错误日志中显示
Flask-0.13.dev0-py2.7
。flask的最新稳定版本是0.12,这是我从源代码处安装的flask版本,因为我怀疑我的flask安装在通过pip安装时不起作用。我试着安装click,但它说它已经安装了。
<Directory flaskapp>
        WSGIProcessGroup flaskapp
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
</Directory>
    Alias /static /var/www/appname/app/static/
    <Directory /var/www/appname/app/>
            Require all granted
    </Directory>
    <Directory /var/www/appname/app/static/>
            Require all granted
    </Directory>