Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask hangs after importing pandas (also numpy, matplotlib etc.)

Why is Flask hanging after importing the pandas lib or several other scientific libs? It still works, when running it locally via SSH, but when visiting the URL the browser loads and loads and nothing happens.

like image 548
baermathias Avatar asked Dec 15 '22 02:12

baermathias


2 Answers

The solution is for Ubuntu with Apache2 server. You have to configure the following file:

/etc/apache2/sites-available/your-flask-app-file.conf

paste the following line below WSGIScriptAlias:

WSGIApplicationGroup %{GLOBAL}  
like image 188
baermathias Avatar answered Mar 25 '23 03:03

baermathias


After a long and painful exercise, I was able to finally get my app running .The issue is with the pandas 0.19.2 built when the application is getting imported in the .wsgi file

To resolve it Remove your imports from the global level and insert them at the function level

import pandas as pd
....
@app.route('/getFunction', methods=["GET"])
def sample_get_function():
    movieData=pd.read_csv('someData.csv')

to

....
@app.route('/getFunction', methods=["GET"])
def sample_get_function():
    import pandas as pd
    movieData=pd.read_csv('someData.csv')

This is not a very good solution but it is working

like image 41
Anant Gupta Avatar answered Mar 25 '23 03:03

Anant Gupta