Still using Python 2? It is time to upgrade.

Most Python programmers agree that Python 3, which has been available since 2008, is a big improvement over Python 2, but many (most?) Python developers are still using Python 2. The main reasons for this, according to a 2014 survey, are:

  1. They are relying on Python 2 libraries that have not been ported to Python 3.
  2. They have a large Python 2 code base, which would be time consuming and difficult to rewrite.
  3. They see no real advantage to switching.

But there are now clear signs that Python 2, which one developer argues we should start calling “Legacy Python”, is on it’s way out. Officially, its “End of Life” is scheduled for 2020 (see PEP 373), which is only four years away. Any Python 2 code written today is not likely to have a long shelf life.

More and more developers are making the switch.

This query of the StackExchange data shows that in Q1, 2016, there have been almost as many Python 3-tagged posts as there were Python 2-tagged posts.

Python Stack Exchange Posts

In Q1, 2014, there were slightly more than 1.71 Python 2 posts for every Python 3 post. Two years later, in Q1, 2016, there are fewer than 1.1 Python 2 posts for every Python 3 post.

Python Stack Exchange Posts as Ratio

We are likely to see a snowball effect here. With Python 2 being officially put to rest in 2020 and as more and more Python 2 packages that developers rely on are ported to Python 3, we will see more and more developers making the switch. I believe the smart decision is to make this switch earlier rather than later.

Google Trends

Another piece of date, which I’m unsure how to interpret but I want to share in case others have thoughts, is this Google Trends chart, which shows that there are about twice as many searches for Python 3 as there are for Python 2 and that this has been the case for some time.

Google Trends: Python 2 v. Python 3

That would seem to indicate that more people are searching for Python 3 resources than for Python 2 resources, but two issues make me wonder if that’s true:

First issue: if you search for anything about Python without specifying the version (e.g., Python Unicode), the first result is almost always the Python 2.7 documentation and the second result is the Python 3.5 documentation. I expect that Google returns the result most people want (i.e., click on) first and its algorithm tells it that people searching for generic Python information are more often looking for Python 2.7 than Python 3.5.  It will be interesting to see when this changes.
Python Unicode Search

Second issue: The slope of the lines is about the same. There were about twice as many Python 3 searches in January, 2016 as there were in January, 2013. And the same is true for Python 2 searches.

Regardless, Python 3 is here to stay and Python 2 is not. So, if you’re writing code in Python 2 today, you may find yourself rewriting or at least reworking that code in the next few years, which won’t be fun.

Also, if you and/or your team are currently learning Python, I agree with the recommendation on that you first learn Python 3. Then, if your project requires you to know Python 2, you learn the differences, which are simple, but could be pervasive, meaning you won’t have any trouble learning and understanding the differences, but you may have to apply them often.

More Resources:

  1. Python usage survey 2014 by Randy Olson
  2. Python 3 will overtake Python 2 in library support in a few months, according to Microsoft’s statistical analysis by Serdar Yegulalp
  3. SQL Query on Stack Exchange comparing Posts tagged Python 2 and Python 3
  4. IPython Notebook on Github showing Python code I used to create plots
  5. Ubuntu finally dropping Python 2.7 in the default installation of 16.04

Related Training: Python

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.

Notice: Undefined variable: separator in D:\\www\blog\wp-content\themes\webucator\single.php on line 55