You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following on from the recent Python version refactoring, this now adds
support for configuring the app's Python version using a
`.python-version` file. This file is used by several tools in the Python
ecosystem (such as pyenv, `actions/setup-python`, uv), whereas the
existing `runtime.txt` file is proprietary to Heroku.
This change is the classic Python buildpack equivalent of the Python
CNB change here:
heroku/buildpacks-python#272
If both a `runtime.txt` file and a `.python-version` file are present,
then the `runtime.txt` file will take precedence. However, use of the
`.python-version` file is now recommended, since `runtime.txt` will
be deprecated in the future. Both the `runtime.txt` file and
`.python-version` file take precedence over any Python version specified
in a `Pipfile.lock` for Pipenv users.
We support the following `.python-version` syntax:
- Major Python version (e.g. `3.13`, which will then be resolved to the
latest Python 3.13). (This form is recommended, since it allows for
Python security updates to be pulled in without having to manually
bump the version.)
- Exact Python version (e.g. `3.13.0`)
- Comments (lines starting with `#`)
- Blank lines
We don't support the following `.python-version` features:
- Specifying multiple Python versions
- Prefixing versions with `python-` (since this form is undocumented
and will likely be deprecated by pyenv in the future)
In addition, the existing `runtime.txt` support has been updated to
allow specifying just the major Python version, in order to increase
feature parity between the files, and avoid confusion if users try to
use the major version only syntax from `.python-version` in their
`runtime.txt`.
Refs #913.
Refs #932.
GUS-W-7671453.
GUS-W-16821357.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
## [Unreleased]
4
4
5
+
- Added support for configuring the Python version using a `.python-version` file. Both the `3.N` and `3.N.N` version forms are supported (the former is recommended). The existing `runtime.txt` file will take precedence if both files are found, however, we recommend switching to `.python-version` since it is more commonly supported in the Python ecosystem. ([#1664](https://github.com/heroku/heroku-buildpack-python/pull/1664))
6
+
- Added support for specifying only the Python major version in `runtime.txt` instead of requiring the full Python version (for example `python-3.N` instead of `python-3.N.N`). ([#1664](https://github.com/heroku/heroku-buildpack-python/pull/1664))
Copy file name to clipboardExpand all lines: README.md
+49-58
Original file line number
Diff line number
Diff line change
@@ -8,61 +8,52 @@ This is the official [Heroku buildpack](https://devcenter.heroku.com/articles/bu
8
8
9
9
Recommended web frameworks include **Django** and **Flask**, among others. The recommended webserver is **Gunicorn**. There are no restrictions around what software can be used (as long as it's pip-installable). Web processes must bind to `$PORT`, and only the HTTP protocol is permitted for incoming connections.
A `requirements.txt` must be present at the root of your application's repository to deploy.
42
-
43
-
To specify your python version, you also need a `runtime.txt` file - unless you are using the default Python runtime version.
44
-
45
-
Current default Python Runtime: Python 3.12.7
46
-
47
-
Alternatively, you can provide a `setup.py` file, or a `Pipfile`.
48
-
Using `pipenv` will generate `runtime.txt` at build time if one of the field `python_version` or `python_full_version` is specified in the `requires` section of your `Pipfile`.
49
-
50
-
Specify a Buildpack Version
51
-
---------------------------
52
-
53
-
You can specify the latest production release of this buildpack for upcoming builds of an existing application:
54
-
55
-
$ heroku buildpacks:set heroku/python
56
-
57
-
58
-
Specify a Python Runtime
59
-
------------------------
60
-
61
-
Supported runtime options include:
62
-
63
-
-`python-3.13.0` on all [supported stacks](https://devcenter.heroku.com/articles/stack#stack-support-details)
64
-
-`python-3.12.7` on all [supported stacks](https://devcenter.heroku.com/articles/stack#stack-support-details)
65
-
-`python-3.11.10` on all [supported stacks](https://devcenter.heroku.com/articles/stack#stack-support-details)
66
-
-`python-3.10.15` on all [supported stacks](https://devcenter.heroku.com/articles/stack#stack-support-details)
67
-
-`python-3.9.20` on all [supported stacks](https://devcenter.heroku.com/articles/stack#stack-support-details)
68
-
-`python-3.8.20` on Heroku-20 only
11
+
## Getting Started
12
+
13
+
See the [Getting Started on Heroku with Python](https://devcenter.heroku.com/articles/getting-started-with-python) tutorial.
14
+
15
+
## Application Requirements
16
+
17
+
A `requirements.txt` or `Pipfile` file must be present in the root (top-level) directory of your app's source code.
18
+
19
+
## Configuration
20
+
21
+
### Python Version
22
+
23
+
We recommend that you specify a Python version for your app rather than relying on the buildpack's default Python version.
24
+
25
+
For example, to request the latest patch release of Python 3.13, create a `.python-version` file in
26
+
the root directory of your app containing:
27
+
`3.13`
28
+
29
+
The buildpack will look for a Python version in the following places (in descending order of precedence):
30
+
31
+
1.`runtime.txt` file (deprecated)
32
+
2.`.python-version` file (recommended)
33
+
3. The `python_full_version` field in the `Pipfile.lock` file
34
+
4. The `python_version` field in the `Pipfile.lock` file
35
+
36
+
If none of those are found, the buildpack will use a default Python version for the first
37
+
build of an app, and then subsequent builds of that app will be pinned to that version
38
+
unless the build cache is cleared or you request a different version.
39
+
40
+
The current default Python version is: 3.12
41
+
42
+
The supported Python versions are:
43
+
44
+
- Python 3.13
45
+
- Python 3.12
46
+
- Python 3.11
47
+
- Python 3.10
48
+
49
+
These Python versions are deprecated on Heroku:
50
+
51
+
- Python 3.9
52
+
- Python 3.8 (only available on the [Heroku-20](https://devcenter.heroku.com/articles/heroku-20-stack) stack)
53
+
54
+
Python versions older than those listed above are no longer supported, since they have reached
0 commit comments