1

I've been trying to get a simple flask app to run but can't get past the following problem.

Lets start with my folder structure:

D:\Git\tools\scripts\simUserInterface with two python files:

app.py

templates.py

In addition, there's the folder

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

with the file web.wsgi

My web.wsgi looks like this:

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

The app.py itself looks like this

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()

I'm using Apache 2.4 and my virtual host configuration looks like this:

<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>

If I run the app with the build-in Flask development server locally on my machine, everything works fine and the layout renders as expected (Of course, my layout is not actually empty. I deleted the code to focus on the main things). However, if I run the script via the browser (127.0.0.1:5000), it seems to be stuck at from templates import MY_TEMPLATE. The browser appears to be loading somethings but doesn't render the layout.

If I comment out that one particular line (from templates import MY_TEMPLATE), everything works fine.

I'm completely out of ideas and any help is appreciated.

icedwater
  • 4,701
  • 3
  • 35
  • 50
  • see this answer https://stackoverflow.com/questions/41099433/flask-hangs-after-importing-pandas-also-numpy-matplotlib-etc – quq Feb 23 '20 at 19:14
  • Can you show your templates.py file? – marcin Mar 09 '20 at 21:06
  • It looks like my problem is that the template.py file imports the pandas module. If I comment out the line where pandas gets imported, everything is loaded correctly. There are several threads were people have reported this issue with Flask/Pandas/Apache/WSGI. I’ll give the proposed solution in quq’s answer a shot and let you know how it went. – pancakeNbacon Mar 11 '20 at 16:52

1 Answers1

2

Thanks to quq's answer, my app is now finally running. Problem summary: - The flask application has problem to import pandas when running in Apache server

Solution:

I had to add the following line at the end of my httpd.conf which is located in the root directory of the Apache installation (for Windows)

WSGIApplicationGroup %{GLOBAL}
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92