Flask deployment issue with imports

I followed this guide.

Most of my files are almost identical to the guide (except FlaskApp is changed to the project name HopUpon). except for which looks like this:

from flask import *
import json
#import airport_finder2
#import pandas as pd
app = Flask(__name__)

def index():
  return render_template('quicksearch.html')

if __name__ == '__main__':

This file works but when I uncomment airport_finder2 or pandas as pd I am unable to reach the website. It endlessly searches.

some background on airport_finder2: this is a python file which searches through two csv files and returns a result. These files are located in the same folder as - /var/www/HopUpon/HopUpon but I would like to move them to /var/www/HopUpon/HopUpon/static once I can get them working.

pandas: I have pip installed pandas on to the virtual environment.

wsgi: I have tried to create a log but I get an internal server error when I do.

import logging
                    format='%(asctime)s %(levelname)-8s %(message)s',
                    datefmt='%a, %d %b %Y %H:%M:%S',
logging.debug('A debug message')

So I have no error logs to show. Apologies. I know it would make it much easer.

My questions: Why are these imports giving errors? What errors are they giving? How do I run my Flask app in debug mode on digitalocean?

Any help will be greatly appreciated.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

hey I figured out my errors.

  1. Hanging request was due to the .conf file. add the code under WSGIScriptAlias
WSGIApplicationGroup %{GLOBAL}
  1. My second error came from trouble my python file had finding a csv file from which it produced results. Interestingly accessing a csv file on a server with python requires you to find the temp location of that file. which is not the same as the static location. so i referred to my cvs inside with:
from pandas import pandas as pd
import os

HERE = os.path.abspath(os.path.dirname(__file__))
file1 = os.path.join(HERE, 'file1.csv')
file2 = os.path.join(HERE, 'file2.csv')

results1 = pd.read_csv(file1)
results2 = pd.read_csv(file2)

I hope this helps others.


To run Flask in debug mode, from the CLI, run:

export FLASK_DEBUG=1

and then

flask run

Keep in mind, once you log out of the current session, you’ll need to run the same export again as it’s only valid for the current session (i.e. you’ll need to run that each time you login).

As for the import, the only details I can find on airport_finder point to airport_finder, as in, without the 2, so have you tried to import using airport_finder instead of airport_finder2?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel