【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
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
Make sure you have choose right one for project, or you get
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
orsetup.py
file in its root directory.Alternatively, you can provide a
setup.py
file, or aPipfile
. UsingPipenv
will generateruntime.txt
based onpython-version
at build time.
If you are using pipfile
, you probably facing the pip version issue
Two solution for this issue
- You have to choose another python buildpack that support newer pip version
- 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