Will Python 2 Ever Die?


Will Python 2 Ever Die?

Python has been having two competing versions co-existing for almost twelve years. Now, that version 2 has officially reached its end of life, but shows no sign of dying out, it’s time to ask: will Python 2 ever die or is it here to stay forever? Let’s find out.

The official support for Python 2 ended on January 1st, 2020 and statistics show that its usage is steadily declining. It is not going to disappear suddenly, but we can expect it to become less and less relevant over the upcoming years.

I did a bit of research to find out what is the current adoption rate of Python 3 and to see if I can give an estimate - based on the current trends - when Python 2 will be completely retired?

Python 2 and 3 - Why Do We Have Two Incompatible Versions?

At the time of its release, Python 3 - besides adding Unicode support and fixing a few other issues - was meant to make the language more streamlined. The goal was to provide a single obvious, idiomatic way to solve common programming tasks. In some cases that involved removing features from the language, so it required a major version bump.

That alone would have been fine, but the early versions of Python 3 were not really production-ready as they were rather slow and buggy. These issues hindered the adoption of the new version, as most organizations were reluctant to make the (at that time rather risky) jump to the new version.

To cater to these less adventurous Python users the core developer team decided to keep maintaining the older version for an extended period of time. As companies were not forced to switch to Python 3, it gained momentum extremely slowly.

It’s true that the base concepts of the language haven’t changed at all, and the syntax - apart from a few exceptions - is almost identical. Also, there are great tools to convert Python 2 code to Python 3 automatically. Despite all this, migrating large codebases can still be problematic.

Python 3 Adoption Over Time

The question is how can we measure the adoption rate of Python 3? We don’t have exact data on the number of CPUs running Python or the number of developers working with it, but there are some representative statistics that could be quite useful. We’ll look at some of these:

Number of Python Developers

JetBrains, the company behind the PyCharm IDE conducts and publishes a yearly developer survey. In 2018 more than 20,000 users participated in the survey. One of the questions they asked from the developers participating, was about the Python version they use.

Here’s the data for the last few years:

Year

Python 2

Python 3

2013

78%

22%

2014

66%

34%

2016

60%

40%

2017

25%

75%

2018

16%

84%

2019

13%

87%

You can check out the original survey results on these links: https://www.jetbrains.com/lp/devecosystem-2019/python/ https://www.jetbrains.com/research/python-developers-survey-2018/ https://www.jetbrains.com/research/python-developers-survey-2017/ https://www.jetbrains.com/pycharm/python-developers-survey-2016/

These numbers show that Python 3 adoption is pretty high among PyCharm users, furthermore it’s growing steadily.

CPython Downloads

In March 2019 Steve Dower, Python core developer published an interesting dataset of the number of downloads of different CPython versions (CPython is the most commonly used implementation of the Python language):

Version

Downloads

Downloads%

3.7.x

15,519,728

58.36%

3.6.x

5,616,969

21.12%

3.5.x

1,187,840

4.47%

3.8.x

156,111

0.59%

2.7.x

4,112,428

15.46%

This data draws a similar picture, if we total the number of downloads across different 3.x version, we can see that they account for 84.63% of all downloads, against Python 2’s 15.46%.

Note: these numbers represent the downloads mainly for windows and macOS users

Number of Python Package Downloads

Another way to look at Python version usage stats is to check the number of downloads of PyPI packages. PyPI provides a publicly accessible API for that.

I pulled the data for some of the most popular packages:

Package

Python 2

Python 3

django

19.96%

78.84%

flask

17.75%

81.76%

pandas

23.34%

76.01%

requests

39.38%

59.92%

There’s quite a bit of variance, but we can see that Python 3 is clearly dominating here as well.

Google Trends is an excellent tool to get a feel for general trends in certain industries. It provides a great visualization for search volume comparisons:

Python 2 vs 3 interest over time

It is a very different approach than comparing the download stats, but the conclusions are somewhat similar. We can see that the interest in Python 3 (marked by red) has taken over a long time ago. Though the overall search volume for Python 2 - thanks to the growing popularity of Python - is still on the rise. It’ll be interesting to keep an eye on this graph in the future.

Which Version Should You Learn in 2020, Python 2 or 3?

It’s been asked many times over the years, but I think the answer has become really obvious by now. In 2020 there is absolutely no reason to choose Python 2 over Python 3.

Python 3 is stable, mature, secure, highly performant and more streamlined - therefore easier to use - than it’s predecessor.

What is the Future of Python 2

My expectation would be to see Python 2 fade away quite soon. I certainly don’t expect it to stay relevant for more than a few years. It’s true that it’s been around for a while and yes, there are ancient languages like Fortran or COBOL that just seem to never die, but I don’t think Python 2 is anything like that. Unlike these systems, Python 2 has a successor and migration to Python 3 is rather simple.

Python 2 has no place anymore in the startup world, no new projects should choose Python 2 to build on. More mature companies with an existing, bigger codebase will also be forced to move to Python 3. With the end of official support for Python 2, maintainability, the lack of security fixes and compliance issues will be a huge driving force for migration.