Flask app deployment - ImportError: No module named 'app'

Flask app deployment - ImportError: No module named 'app'

一个奇怪的 - 我已经尝试并试图让这个 Flask 应用程序运行 - 似乎出了点问题。

Flask 应用程序内的

$ pwd 给出:

/home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos

Flask 应用程序中的

$ ls 给出:

__init__.py  __pycache__  vexxos.py  windupflaskvexxos.wsgi

__init__.py 为空。

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

然而我在前端看到的是:

/etc/apache2/site-available/000-default.conf:

<VirtualHost *:80>

        ServerAlias flask.winduplordvexxos.com
        ServerAdmin admin@winduplordvexxos.com

        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>

检查 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): 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'

我已经尝试了很多东西,尝试除了模块导入等,但似乎没有任何效果......有人可以帮忙吗?

您可能需要告诉 mod_wsgi 您的代码在哪里使用 WSGIDaemonProcesspython-path 选项。您在 WSGI 脚本文件中的导入看起来也是错误的。

python-path 你可能想要:

python-path=/home/winduplordvexxos/winduplordvexxos.com

那么导入应该是:

from windupflaskvexxos import app as application

或者如果 app 没有被 __init__.py 引入,使用:

from windupflaskvexxos.vexxos import app as application

另请阅读使用 mod_wsgi 设置虚拟环境的首选方法。您使用的方式不是推荐的方式。