Specifying a Python Runtime
Last updated November 08, 2021
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 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.10.0
runtime.txt format is case-sensitive and must not include spaces. You must also specify all three version number components (major, minor, and patch) in
If you don’t follow this format, 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.10.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