Python 2.7 EOL FAQ
Last updated October 13, 2022
Table of Contents
- Why is Python 2 being sunset?
- What Heroku stack versions support Python 2?
- What will happen to existing Python 2 apps on Heroku?
- Will Python 2 apps still receive technical support?
- How do I migrate my application to Python 3?
- I’m not going to be able to migrate to Python 3, what are my options?
- How do I switch to a Python buildpack version that still supports Python 2?
Why is Python 2 being sunset?
Python 2 was superseded by Python 3 many years ago, and as such the upstream Python project officially ended support for Python 2 on January 1st, 2020, after several extensions to the sunset date. This means no new versions of Python 2 are being released upstream, so it no longer receives security or bug fixes.
What Heroku stack versions support Python 2?
What will happen to existing Python 2 apps on Heroku?
Existing Python 2.7 applications on Heroku will continue to run for the foreseeable future (unless impacted by issues unrelated to the Python version).
- Since Python 2 has not received security fixes since 2020, it contains several unfixed security vulnerabilities, and so customers are strongly encouraged to migrate to a newer Python version to keep their applications secure.
- The latest version of the Python buildpack no longer supports Python 2, so apps must switch to an older buildpack version in order for builds to work (see How do I switch to a Python buildpack version that still supports Python 2?).
- Once the deprecated Heroku-18 stack reaches the end of it’s life on April 30th, 2023, further builds (code deployments) of Python 2 apps will no longer be possible (even when using the older buildpack version), since newer stacks do not support Python 2. See the Heroku-18 End-of-Life FAQ for more details.
Will Python 2 apps still receive technical support?
End of life language versions fall outside of Heroku’s Support Policy, and so Python 2 applications are no longer eligible for technical support without first upgrading to a supported version of Python.
How do I migrate my application to Python 3?
See the upstream Python project’s guide to Porting Python 2 Code to Python 3.
Once your application has been made compatible with Python 3 locally, you will then need to ensure that Heroku builds your application using Python 3. See Specifying a Python Runtime and supported Python versions.
I’m not going to be able to migrate to Python 3, what are my options?
Python 2 contains several unfixed security vulnerabilities, and so customers are strongly encouraged to migrate to a newer Python version to keep their applications secure. However, if you are willing to accept this risk there are two ways you can continue to use Python 2:
- If your application does not need any further code changes/new deployments, you can continue using your existing Python 2 application even after the end-of-life of the Heroku-18 stack with no changes required (see the Heroku-18 End-of-Life FAQ for more details).
- However, if you wish to continue performing new code deployments after the Heroku-18 stack reaches end-of-life (on April 30th, 2023), one alternative would be to migrate to Heroku’s
containerstack instead, and use the legacy
python:2.7Docker images (note: these Docker images have not received security updates since 2020 either). See:
How do I switch to a Python buildpack version that still supports Python 2?
The latest version of the Heroku Python buildpack (the component responsible for transforming your source code into a deployable application) no longer supports Python 2 as of September 26th, 2022.
Therefore, in order to continue to build Python 2 applications (until the end-of-life of Heroku-18), you will need to switch to an older version of the Python buildpack. Note: This should only be used as a temporary solution until either the app is upgraded to Python 3, or one of the longer-term workarounds above is used.
To do this, follow the steps at Checking the Python buildpack version, except instead of specifying a buildpack URL of
heroku/python, use the URL
https://github.com/heroku/heroku-buildpack-python#v218 instead, which will mean your app will use version 218 of the buildpack (the last to support Python 2).
Once you have upgraded your app to Python 3, make sure to undo this change, by following the same process and switching back to a buildpack URL of
heroku/python, to ensure you receive future fixes and updates to the Python buildpack.