Specifying a Python Runtime
Last updated November 06, 2023
Table of Contents
By default, new Python applications on Heroku use the Python runtime indicated in Specifying a Python version.
If you’re running a Python application that requires a different supported runtime, or if you 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.11.6
The runtime.txt
format is case-sensitive and must not include spaces. You must also specify the python-
prefix and all three version number components: major, minor, and patch.
Your app fails to deploy if you don’t follow this format.
To check which version of Python you’re running locally, activate your virtual environment and check with the -V
flag.
$ python -V
Python 3.11.6
Whenever you change Python runtime versions, your dependency cache clears and you must reinstall all dependencies.
We recommend specifying 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