Specifying a Python Version
Last updated December 03, 2024
Table of Contents
By default, newly created Python apps use the latest patch version of Python 3.12. Subsequent builds of the app will then be pinned to that initial Python version unless the build cache is cleared or you request a different version.
However, we recommend that you specify a Python version for your app rather than relying on the default version.
Selecting a Runtime
To specify a Python runtime, add a .python-version
file (note the leading .
in the filename) to your
app’s root directory that declares the Python version number to use.
This version can be either:
- The major Python version such as
3.13
(recommended) - The full Python version such as
3.13.0
We recommend specifying only the major version (e.g. 3.13
), so that your app is automatically built with the
latest Python security patches.
For example:
$ cat .python-version
3.13
To check which version of Python you’re running locally, activate your virtual environment and run python --version
:
$ python --version
Python 3.13.0
The runtime.txt
file is deprecated. If your app uses it, we recommend switching to a .python-version
file instead,
since it’s more widely supported by other tooling in the Python ecosystem.