【问题标题】:Why is my Flask app stuck at import step? [duplicate]为什么我的 Flask 应用程序卡在导入步骤? [复制]
【发布时间】:2020-02-04 14:47:27
【问题描述】:

我一直在尝试运行一个简单的烧瓶应用程序,但无法解决以下问题。

让我们从我的文件夹结构开始:

D:\Git\tools\scripts\simUserInterface 带有两个 python 文件:

app.py

templates.py

另外还有文件夹

D:\Git\tools\scripts\simUserInterface\index

与文件 web.wsgi

我的 web.wsgi 看起来像这样:

import sys
sys.path.insert(0, 'D:/Git/tools/scripts/simUserInterface')
from dashy import server as application

app.py 本身看起来像这样

import os
import sys
from flask import Flask
import dash
import dash_table
import dash_html_components as html
import dash_core_components as dcc
from templates import MY_TEMPLATE

server = Flask(__name__)
app = dash.Dash(__name__, server=server)

# Create app layout
app.layout = html.Div()

if __name__ == "__main__":
    server.run()

我使用的是 Apache 2.4,我的虚拟主机配置如下所示:

<VirtualHost *:5000>
    ServerAdmin admin-name-here
    ServerName  localhost:5000
    WSGIScriptAlias / "D:/Git/tools/scripts/simUserInterface/index/web.wsgi"
    DocumentRoot "D:/Git/tools/scripts/simUserInterface"
    <Directory "D:/Git/tools/scripts/simUserInterface/index">
            Require all granted
    </Directory>
    ErrorLog "D:/Git/tools/scripts/simUserInterface/logs/error.log"
    CustomLog "D:/Git/tools/scripts/simUserInterface/logs/access.log" common
</VirtualHost>

如果我在我的机器上本地运行带有内置 Flask 开发服务器的应用程序,一切正常并且布局按预期呈现(当然,我的布局实际上不是空的。我删除了代码以专注于主要事物)。 但是,如果我通过浏览器 (127.0.0.1:5000) 运行脚本,它似乎卡在 from templates import MY_TEMPLATE。浏览器似乎正在加载某些内容,但未呈现布局。

如果我注释掉某一行(from templates import MY_TEMPLATE),一切正常。

我完全没有想法,感谢任何帮助。

【问题讨论】:

  • 你能显示你的templates.py文件吗?
  • 看来我的问题是 template.py 文件导入了 pandas 模块。如果我注释掉导入 pandas 的行,则所有内容都已正确加载。有几个线程有人报告了 Flask/Pandas/Apache/WSGI 的这个问题。我将在 quq 的回答中给出建议的解决方案,并让你知道它是如何进行的。

标签: python apache flask mod-wsgi plotly-dash


【解决方案1】:

感谢 quq 的回答,我的应用程序现在终于可以运行了。 问题总结: - 烧瓶应用程序在 Apache 服务器中运行时导入 pandas 时出现问题

解决方案:

我必须在我的 httpd.conf 末尾添加以下行,该文件位于 Apache 安装的根目录(对于 Windows)

WSGIApplicationGroup %{GLOBAL}

【讨论】:

  • 在 Ubuntu 上也遇到了同样的问题,这解决了。
猜你喜欢
  • 2021-10-18
  • 1970-01-01
  • 1970-01-01
  • 2019-06-18
  • 2018-01-15
  • 1970-01-01
  • 2015-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多