This guide assumes you have a working Python Flask app and have Heroku-CLI installed on your machine.
-
Install the gunicorn server:
pip install gunicorn
-
Install all other dependencies:
pip install flask
pip install flask-sqlalchemy
pip install pandas
...
- Run the command:
pip freeze > requirements.txt
This command will create a requirements.txt file in the current directory that includes all our dependencies (Python packages we use). Heroku will use this file to install all the required dependencies for our app.
-
Create a
Procfile
file (command:touch Procfile
). -
Open (edit)
Procfile
and add the following line to it:
web: gunicorn <app-folder-name>.app:app
(replacing <app-folder-name>
with the name of the folder that contains your __init__.py
file)
This file will be used by Heroku to start the gunicorn server and run our app.
-
Using the command-line login to heroku:
heroku login
and enter your credentials. -
Create an Heroku app with the command:
heroku create
-
Add, Commit and Push your app to Heroku:
git add .
git commit -m 'heroku deployment'
git push heroku master
- You are now successfully deployed!