Python 2 is no longer supported by the Python Software Foundation. Hereโs what you can do if youโre stuck with Python 2 in what is fast becoming a Python 3 world
As of January 1, 2020, the 2.x branch of the Python programming language is no longer supported by its creators, the Python Software Foundation. This date marks the culmination of a drama that has stretched on for yearsโthe transition from an older, less capable, widely used version of Python to a newer, more powerful version that still trails its predecessor in adoption.
Itโs high time. Python 3, with countless technical and end-user enhancements over Python 2, has never been in a better position to permanently displace Python 2. The vast majority of popular packages hosted in the PyPI repository, the first-stop shop for reusable Python code, support Python 3. Python 3 has become the default Python interpreter for many Linux distributions. And most every recent book, coding academy, and online tutorial recommends Python 3 for beginners.
Now the bad news. Python 2, like Windows 7 (or Windows XP!), will be with us for years to come. Many of us will continue to rely on apps written in Python 2. Some of us will even continue to use Python 2 for new apps, due to internal restrictions. What should you do if youโre stuck with Python 2 in what is fast becoming a Python 3 world? Letโs look at the options.ย
Python 2 end of life: What it means
The first and most important thing to understand about Python 2 going EOL (end of life): Python 2 applications will still run. Donโt think of this as a Millennium Bug issue, where Python 2 applications all magically grind to a halt on January 1, 2020. There just wonโt be any more official supportย for Python 2 from the core Python development team.
Here is what the Python 2 EOL means in practical terms:
- Official bug fixes and security patches for Python 2 will cease.ย No newly discovered problems in the Python 2 interpreter or the Python 2 standard library will be fixed by the core development team. However, commercial vendors could maintain Python 2 on their own, and other third parties could fork the Python 2 codebase and continue where the core team left off. (More on this later.)
- Third-party Python projects will abandon Python 2. Libraries that have supported both Python 2 and Python 3 will begin to devote their resources to Python 3 exclusively. Many of these projects are volunteer-run, and itโs far less work to support just one version of the language. Each project will decide on Python 2 support for itself, but many major Python projects are pledging to drop Python 2 support entirely by 2020.
- Platform support for Python 2 will wane. Linux distributions and cloud service providers may continue to include the Python 2 runtime. But expect support for Python 2 to become less robust over time. It will almost certainly still be possible to run a containerized version of Python 2 on a cloud platform, but thereโs no guarantee that cloud service providers will continue to maintain their own Python 2 containers.
If you are stuck with Python 2 applications, how should you deal with the absence of Python 2 support? The best thing to do in the long term is find a strategy to remove all of your dependencies on Python 2. But that is just the first of many options.ย
Transition away from Python 2
Leaving behind Python 2 forย Python 3 may be easier than you expect, depending on the size of the code base and the external dependencies. Pythonโs official documentation has some straightforward steps you can take to determine if your project is โfuture-proofโโi.e., can be used in Python 3 with little or no adjustment.ย One of the best first steps you can take is to use theย caniusepython3 package to figure out which, if any, components or dependencies would block a migration.
If youโre stuck with Python 2 because a particular component of an application works only on Python 2, start by transitioning away from that component. See if an alternative exists that is Python 3 compatible, and then rebuild the application from that point outwards. The idea is to look for the smallest places where oneโs dependencies on Python 2 lie, and address them.
Theย very least you can do, if you must remain on Python 2 in some form, is start by migrating to the latest version of Python 2โPython 2.7.16 as of this writingโand use that as the point of departure for Python 3. That way youโll benefit from the bug fixes that will be available for Python 2.7 before its official end of life.
Use an alternative Python 2 runtime
If altering the Python 2 code base isnโt a workable proposition, another alternative is to use a different Python 2 runtime, developed by a third party. Alternative Python 2 runtimes may have a longer support window than Python 2 itself.
Tauthon
Tauthon is a fork of Python 2.7.18 โwith new syntax, built-ins, and libraries backported from Python 3.x,โ according to the projectโs README. Tauthon also includes, whenever the maintainers can provide them, fixes and patches for the language. In theory Tauthon should work as a drop-in replacement for Python 2.7. The most recent release as of this writing, Tauthon 2.8.2, includes function annotations, keyword-only arguments, async/await syntax, and other features formerly available only in Python 3.
PyPy
PyPy, the just-in-time accelerated runtime for Python, uses Python 2 as a key part of its own internal infrastructure, and has long supported Python 2 as its main version. The documentation for the project claims โsince RPython [the foundation of PyPy] is built on top of Python 2 and that is extremely unlikely to change, the Python 2 version of PyPy will be around โforever,โ i.e. as long as PyPy itself is around.โ PyPy might pose compatibility or performance problems with some Python packages that rely on C extensions, although PyPyโs development team works constantly to iron out those issues.
IronPython
IronPython, a Python implementation for the .Net runtime, has a Python 2 version still receiving active support. Its current roster of developers have declared they are not likely to support Python 2 past 2020, the better to concentrate on IronPython3. However, that doesnโt mean someone else couldnโt continue such support on their own.
Cython
Another possibility, although with a limited window of support as well, is Cython. Cython compiles Python to C with optional typing for performance enhancements and has supported Python 2 since its inception. Itโs possible to use Cython to convert Python 2 code into C for continued use as a โfrozenโ binary. You might even gain a performance boost by doing so, depending on the nature of the application. (Programs that are mainly I/O bound wonโt see much improvement.)
However, Cython plans to drop Python 2 support by the end of the year.ย This doesnโt mean that Python 2 programs wonโt compile to Cython anymore, only that Cython code using Python 2 syntax would need to be compiled using Python 3.ย
Buy extended Python 2 support from a vendor
One long-term solution is to obtain support from a vendor of Python solutions. ActiveState, creator of the ActivePython distribution and the Komodo IDE, offers commercial support for customers who want to stay with Python 2, or who want to migrate to Python 3 by identifying the parts of their Python stack that must be rewritten in Python 3.
Some vendors provide support for Python 2 as part of its presence in another supported product. Red Hat Enterprise Linux versions 6 and 7 include Python 2, so any support contracts purchased from Red Hat for those versions of the OS will include continuing support for Python 2ย through the support lifetime of the product.
If youโre using Python 2 by way of a cloud service, thereโs a chance the service will continue to support Python 2 in its own way. AWS, for instance, has stated it will provide security patches for its Python 2.7 runtime until December 31, 2020, although this does not apply to any third-party Python 2.7 packages.
A third option is to purchase support from a consulting firm or contractor. The level of support they give you would vary depending on your needs and ambitions. It could consist of coming up with a transition plan to move away from Python 2 and having any dependent software rewritten (probably the best long-term strategy), or manually merging patches for Python 2 into a custom build of the runtime (ambitious and complex).
Maintain Python 2 yourself
Python is an open source project. Thereโs nothing to stop you from implementing any needed fixes yourself. If the fix is a change to Pythonโs standard library, that typically isnโt too hard, as most of the Python standard library is itself written in Python. But if you need to make changes to a C module used by Python in the standard library, or the CPython interpreter, that would be more challenging. Youโll need to know C and be familiar with CPythonโs internals to accomplish this.
Do nothing
If it ainโt broke, donโt fix it. Thatโs the strategy many businesses used with Windows NT and Windows 2000 when those operating systems went end-of-life. Python applications that are for internal use only and that arenโt exposed to the public Internet could in theory be run indefinitely.
Virtual machines and containerization provide ways to keep these kinds of applications alive and well in a controlled environment.ย You canย โfreezeโ a given edition of the Python 2 runtime into a container image or VM, along with its standard library, the modules needed for your app, and the application itself.
That said, any legacy app, even one that has no external exposure, should be reassessed regularly. In every case, the best long-term strategy for Python 2 users is to migrate to Python 3. Python 2, as great as it has been, is something to move past.


