【Heroku】Figure out how to setup Python environment

This article is for programmer who use Heroku nebie and has been login into Heroku in Terminal

Zam Huang
2 min readFeb 18, 2020

First, you have to prepare files for python buildpack

There are many of buildpacks to use, and you could build your own pack, use Heroku and contributors work.

Terminal:

heroku buildpacks:add heroku/python

On Web:

find your pack on internet, and add build at https://dashboard.heroku.com/apps/{app_name}/settings

Add buildpacks

Make sure you have choose right one for project, or you get

Not add any buildpacks
Use wrong buildpack

Second, Check required files

Prepare runtime.txt and requirements.txt is a good choice, this might avoid some problems when doing the build

runtime.txt

python-3.7.6

requirements.txt

pip freeze > requirements.txt

Heroku automatically recognizes your app as a Python app if it includes a requirements.txt or setup.py file in its root directory.

Alternatively, you can provide a setup.py file, or a Pipfile. Using Pipenv will generate runtime.txt based on python-version at build time.

If you are using pipfile, you probably facing the pip version issue

pip version error

Two solution for this issue

  1. You have to choose another python buildpack that support newer pip version
  2. Fork the Heroku/heroku-build-pack project and update “PIP_UPDATE” to the right version in Heroku/…/bin/compile, then add the url from forked project as buildpack to Heroku web or terminal

Reference

If you like this one or feel helpful, please applause or follow to Zam, I am really appreciate you doing that

--

--

Zam Huang
Zam Huang

Written by Zam Huang

一個記錄著自己人生過程的工程師。A Software Engineer at Ruckus Network in Taiwan。 IG, Linkedin:@zam_huang, stack overflow: user:2613194

No responses yet