问题描述
奇怪的一个 - 我已经尝试过,并试图让这个Flask应用程序 - 东西似乎出了错。 $ pwd
在Flask应用程序中给出:
/home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos
$ ls 给出:
__ init__.py __pycache__ vexxos.py
c>是空的。
vexxos.py :
从烧瓶导入烧瓶
app =烧瓶(__ name__)
@ app.route('/')
def api():
return'上传Vexxos API'
if __name__ ==__main__:
app.run(host ='0.0.0.0')
windupflaskvexxos.wsgi :
activate_this ='/home/winduplordvexxos/winduplordvexxos.com/winduplordvexxos_env/bin/activate_this.py'
$ p $然而,我在前面看到的是:
with open(activate_this)as file_:
exec(file_.read(),dict(__ file __ =激活这个))
导入os,sys
cwd = os.getcwd()
sys.path.insert(0,cwd)
从.vexxos导入应用程序中的
作为应用程序
除了例外情况:#ImportError $ b $从vexxos导入应用程序作为应用程序
/etc/apache2/site-available/000-default.conf :
< VirtualHost *:80> ;
ServerAlias flask.winduplordvexxos.com
ServerAdmin [email protected]
WSGIDaemonProcess windupflaskvexxos.com user = winduplordvexxos group = winduplordvexxos threads = 5
WSGIScriptAlias / /home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos/windupflaskvexxos.wsgi
< Directory /home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos/>
WSGIProcessGroup windupflaskvexxos.com
WSGIApplicationGroup%{GLOBAL}
WSGIScriptReloading On
要求所有被授予
< / VirtualHost>
检查apache错误日志给了我:
[Fri Oct 13 23:05:14.650945 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] mod_wsgi(pid = 15561):目标WSGI脚本'/ home / winduplordve $
[Fri Oct 13 23:05:14.651088 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] mod_wsgi(pid = 15561) :处理WSGI scr $
[Fri Oct 13 23:05:14.657996 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] Traceback(最近一次调用的最后一个):
[Fri Oct 13 23:05:14.658060 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] File/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.658071 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] from .vexxos import app as application
[Fri Oct 13 23: 05:14.658098 2017] [wsgi:error] [pid 15561:tid 1 40103054321408] [remote 109.149.163.9:59859] SystemError:父模块''未加载,无法执行rel $
[Fri Oct 13 23:05:14.658131 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859]
[Fri Oct 13 23:05:14.658146 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859]在处理上述异常期间,另一个例外事件$
[Fri Oct 13 23:05:14.658156 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859]
[Fri Oct 13 23:05 :14.658180 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859]追溯(最近一次通话最后):
[Fri Oct 13 23:05:14.658229 2017] [wsgi:错误] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859]文件/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.658248 2017] [wsgi:error]从vexxos导入应用程序[bid 15561:tid 140103054321408] [remote 109.149.163.9:59859]作为应用程序
[Fri 10月13日23:05:14.658286 2017] [wsgi:错误] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] ImportError:没有模块名为'vexxos'
[Fri Oct 13 23:05:14.690252 [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] mod_wsgi(pid = 15561):Target WSGI script'/ home / winduplordve $
[Fri Oct 13 23:05: 14.690318 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] mod_wsgi(pid = 15561):处理WSGI scr $
[Fri Oct 13 23:05:14.690468 2017 [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858]追踪(最近一次通话最后):
[Fri Oct 13 23:05:14.690515 2017] [wsgi:error] [wsgi:error] [ pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] File/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.690525 2017] [wsgi:error] [pid 15561 :tid 140103087892224] [remote 109.149.163.9:59858] from .vexxos import app as application
[Fri Oct 13 23:05:1 [错误] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] SystemError:父模块''未加载,无法执行$
[Fri Oct 13 23:05:14.690566 2017 ] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858]
[Fri Oct 13 23:05:14.690573 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858]在处理上述异常期间,另一个异常oc $
[Fri Oct 13 23:05:14.690577 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9: 59858]
[Fri Oct 13 23:05:14.690589 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858]追踪(最近一次调用最后):
[ Fri Oct 13 23:05:14.690610 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] File/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.690619 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] from vexxos导入应用程序
[Fri Oct 13 23:05:14.690637 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] ImportError:没有名为'vexxos'的$ b $ $ b我已经尝试了很多东西,除了在模块导入等尝试,但似乎没有任何工作..有人可以帮忙吗?
解决方案您可能需要告诉mod_wsgi您的代码正在使用python-path
选项到WSGIDaemonProcess
。您在WSGI脚本文件中的导入也看起来是错误的。
对于
python-path
您可能想要:python-path = / home / winduplordvexxos / winduplordvexxos.com
导入应该是:
从windupflaskvexxos导入应用程序作为应用程序
或者
app
不被
$ b $ p $$ c> __ init __。py
$ b还请阅读使用mod_wsgi设置虚拟环境的首选方法。您使用的方式不是推荐的方式。
Strange one - I've tried and tried to get this Flask app going - something seems to be going wrong.
$ pwd
inside the Flask app gives:/home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos
$ ls
inside the Flask app gives:__init__.py __pycache__ vexxos.py windupflaskvexxos.wsgi
__init__.py
is empty.vexxos.py:
from flask import Flask app = Flask(__name__) @app.route('/') def api(): return 'Wind Up Lord Vexxos API' if __name__ == "__main__": app.run(host='0.0.0.0')
windupflaskvexxos.wsgi:
activate_this = '/home/winduplordvexxos/winduplordvexxos.com/winduplordvexxos_env/bin/activate_this.py' with open(activate_this) as file_: exec(file_.read(), dict(__file__=activate_this)) import os, sys cwd = os.getcwd() sys.path.insert(0, cwd) try: from .vexxos import app as application except Exception: #ImportError from vexxos import app as application
However, all I see on the front end is:
/etc/apache2/site-available/000-default.conf:
<VirtualHost *:80> ServerAlias flask.winduplordvexxos.com ServerAdmin [email protected] WSGIDaemonProcess windupflaskvexxos.com user=winduplordvexxos group=winduplordvexxos threads=5 WSGIScriptAlias / /home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos/windupflaskvexxos.wsgi <Directory /home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos/> WSGIProcessGroup windupflaskvexxos.com WSGIApplicationGroup %{GLOBAL} WSGIScriptReloading On Require all granted </Directory> </VirtualHost>
Checking the apache error logs has given me:
[Fri Oct 13 23:05:14.650945 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] mod_wsgi (pid=15561): Target WSGI script '/home/winduplordve$ [Fri Oct 13 23:05:14.651088 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] mod_wsgi (pid=15561): Exception occurred processing WSGI scr$ [Fri Oct 13 23:05:14.657996 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] Traceback (most recent call last): [Fri Oct 13 23:05:14.658060 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$ [Fri Oct 13 23:05:14.658071 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] from .vexxos import app as application [Fri Oct 13 23:05:14.658098 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] SystemError: Parent module '' not loaded, cannot perform rel$ [Fri Oct 13 23:05:14.658131 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] [Fri Oct 13 23:05:14.658146 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] During handling of the above exception, another exception oc$ [Fri Oct 13 23:05:14.658156 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] [Fri Oct 13 23:05:14.658180 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] Traceback (most recent call last): [Fri Oct 13 23:05:14.658229 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$ [Fri Oct 13 23:05:14.658248 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] from vexxos import app as application [Fri Oct 13 23:05:14.658286 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] ImportError: No module named 'vexxos' [Fri Oct 13 23:05:14.690252 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] mod_wsgi (pid=15561): Target WSGI script '/home/winduplordve$ [Fri Oct 13 23:05:14.690318 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] mod_wsgi (pid=15561): Exception occurred processing WSGI scr$ [Fri Oct 13 23:05:14.690468 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] Traceback (most recent call last): [Fri Oct 13 23:05:14.690515 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$ [Fri Oct 13 23:05:14.690525 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] from .vexxos import app as application [Fri Oct 13 23:05:14.690549 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] SystemError: Parent module '' not loaded, cannot perform rel$ [Fri Oct 13 23:05:14.690566 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] [Fri Oct 13 23:05:14.690573 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] During handling of the above exception, another exception oc$ [Fri Oct 13 23:05:14.690577 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] [Fri Oct 13 23:05:14.690589 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] Traceback (most recent call last): [Fri Oct 13 23:05:14.690610 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$ [Fri Oct 13 23:05:14.690619 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] from vexxos import app as application [Fri Oct 13 23:05:14.690637 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] ImportError: No module named 'vexxos'
I've tried a number of things, try except on the module import etc but nothing seems to work...can anyone help with this?
解决方案You likely need to tell mod_wsgi where your code is using the
python-path
option toWSGIDaemonProcess
. Your import in the WSGI script file also looks wrong.For
python-path
you likely want:python-path=/home/winduplordvexxos/winduplordvexxos.com
The import should then be:
from windupflaskvexxos import app as application
or if
app
not pulled in by__init__.py
, use:from windupflaskvexxos.vexxos import app as application
Also read up on the preferred way of setting up a virtual environment with mod_wsgi. The way you are using is not the recommended way.
这篇关于Flask应用程序部署 - ImportError:没有名为“app”的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-20 07:15