> /dev/null

Interesting hacks, snippets, and shortcuts.

Jan 2

Managing $PYTHONPATH on Heroku

I have a Flask application that I wanted to host on Heroku. This is normally very simple, but I put my code in a src/ subdirectory which means I need $PWD/src on my PYTHONPATH.

Googling reveals some people adding a Heroku config variable like so:

heroku config:add PYTHONPATH=...

I don't like this solution for 2 reasons. First, I have to already know the existing $PYTHONPATH and well as the path to my code. Second, this directory is not a configuration detail; it will always be the same regardless of where I deploy.

The solution I ended up with is to simply set the PYTHONPATH variable in my Procfile using the env utility.

web: env PYTHONPATH=$PYTHONPATH:$PWD/src gunicorn app:app