Specifying a Python Runtime
Last updated 17 August 2018
By default, new Python applications on Heroku use the Python runtime indicated in Supported Python Runtimes.
If you’re running a Python application that requires a different supported runtime, or if you simply want to lock your project against patch updates until you’re ready to upgrade, you can specify which runtime to use for your app.
Selecting a runtime
To specify a Python runtime, add a
runtime.txt file to your app’s root directory that declares the exact version number to use:
$ cat runtime.txt python-3.7.0
You must specify all three version number components (major, minor, and patch) in
runtime.txt. If you don’t, your app will fail to deploy.
To check which version of Python you’re running locally, activate your virtual environment and check with the
$ python -V Python 3.7.0
Whenever you change Python runtime versions, your dependency cache is cleared, and all dependencies need to be reinstalled.
It’s recommended to specify explicit dependency versions in your
requirements.txt file. To update this file, you can use the
pip freeze command in your active virtual environment:
$ pip freeze > requirements.txt