我正在尝试使用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
这是我的烧瓶。wsgi脚本
import sys
sys.path.insert(0,'/var/www/html/flaskapp')
from flaskapp import app as application
这是我的烧瓶程序:
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
我遗漏了什么?谢谢
编辑:这是我的默认设置。形态
<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
我今天正在处理这个问题。如果您使用的是Apache 2.4,这是一个简单的更改:
<Directory flaskapp>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
收件人:
<Directory flaskapp>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
更多信息请点击此处:http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/#configuring-阿帕奇
此外,不确定它是否有所不同,但我的目录是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>
我有一个基本的“hello world”烧瓶应用程序正在运行。 我在Ubuntu 14.04上,使用Apache 2.4。我安装了mod_wsgi。 我创建了一个~/web/piFlask/venv/来保存一个安装了flask的virtualenv创建的Python2。 但是,我希望我的flaskapp导入我编写的Python3. x模块。 我需要做什么才能做到这一点? 我试着创建一个
在CentOS 6.4中,我在/var/www/html/venv文件夹中创建了python虚拟环境。然后在激活虚拟环境后,我为我的flask应用程序安装了所有必要的python库。我检查了一下,Flask库位于/var/www/html/venv/lib/python2.7/site-packages文件夹中。我已经安装并加载了mod_wsgi。现在,在我的flask应用程序中(位于/var/w
我试图在python中构建一个可以从XAMPP的Apache运行的应用程序,因此我安装了flask(),并按照以下说明进行mod_wsgi安装http://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html.我使用XAMPP的Apache,版本2.4.29和anaconda的python 3.6.4
任何人请建议如何摆脱已经运行的应用程序。我试过很多关于杀戮过程的东西,但没有一个是真的奏效的。
我正在建立一个小网站,我已经在SQLAlChemy中拥有了我所有的模型。该网站将发布一些离线计算的信息。只有结果将被发布到一个精简的数据库,即它包含结果,而不是原始数据,但网站需要查询结果。 我将使用Flask,因为我的模型已经用Python驱动了(通过SWIG在C中进行了一些繁重的工作),我不想使用Django。 我敢肯定,以前有人问过这个问题,通常没有太多理由的咒语是“使用炼金术”。问题是为什
我当前在运行flask代码时遇到以下错误: 瓶子调试助手。FormDataRoutingRedirect-FormDataRoutingRedirect:已向此URL发送请求(http://localhost:5000/login)但路由系统自动发出重定向到“http://localhost:5000/login/“。URL是用尾随斜杠定义的,因此如果在没有尾随斜杠的情况下访问,Flask将自动重