Posted on

Should I use Python 2 or Python 3 for my development activity?

thinker-28741_640Python is without any doubt one of the most talked about programming language in this Universe. It’s everywhere, and because of how simple it is to learn it – many beginners start their career with Python. The syntax of Python is very similar to that of English language, with the exception of a few extra characters here and there. Currently there are two main versions of Python, Python 2 and Python 3, that have slight differences in their syntax and their support of different libraries. You can refer this post to know the key differences between Python 2 and Python 3.

No doubt both versions of Python are good but many a times, beginners get confused while choosing one of the two for their development purpose. In this article I will try to explain which Python version can you use to start your development.

What are the differences?

Short version: Python 2.x is legacy, Python 3.x is the present and future of the language

In order to avoid making this post too long, I will be avoiding the details of differences between the two versions. The detailed post on differences between Python 2 and Python 3 can be found here.

Which version should I use?

Which version you ought to use is mostly dependent on what you want to accomplish.

If you can do exactly what you want with Python 3.x, great! There are a few minor downsides, such as very slightly bad library support and the fact that some current Linux distributions and Macs are still using 2.x as default (although Python 3 ships with many of them), but as a language Python 3.x is definitely ready. As long as Python 3.x is installed on your user’s computers (which ought to be easy, since many people reading this may only be developing something for themselves or an environment they control) and you’re writing things where you know none of the Python 2.x modules are needed, it is an excellent choice. Also, most Linux distributions have Python 3.x already installed, and available for end-users. Some are phasing out Python 2 as pre-installed default.

In particular, instructors introducing Python to new programmers should consider teaching Python 3 first and then introducing the differences in Python 2 afterwards (if necessary), since Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers trying to learn Python 2.

However, there are some key issues that may require you to use Python 2 rather than Python 3.

  • Firstly, if you’re deploying to an environment you don’t control, that may impose a specific version, rather than allowing you a free selection from the available versions.
  • Secondly, if you want to use a specific third party package or utility that doesn’t have a released version that is compatible with Python 3, and porting that package is a non-trivial task, you may choose to use Python 2 in order to retain access to that package.

Python 3 already broadly supports creating GUI applications, with Tkinter in the standard library. Python 3 has been supported by PyQt almost from the day Python 3 was released; PySide added Python 3 support in 2011. GTK+ GUIs can be created with PyGObject which supports Python 3 and is the successor to PyGtk.
Many other major packages have been ported to Python 3 including:

  • NumPy and SciPy (for number crunching and scientific computing)
  • Django, Flask, CherryPy and Pyramid (for Web sites)
  • NumPy and SciPy (for number crunching and scientific computing)
  • Django, Flask, CherryPy and Pyramid (for Web sites)
  • And many, many more!

If you want to use Python 3.x, but you’re afraid to because of a dependency, it’s probably worthwhile doing some research first. This is a work in progress. Furthermore, with the large common subset supported by both Python 2.6+ and Python 3.3+, many modern Python code should run largely unmodified on Python 3, especially code written to interoperate with web and GUI frameworks that force applications to correctly distinguish binary data and text (some assistance from the six compatibility module may be needed to handle name changes).

Even though the official python documentation and the tutorial have been completely updated for Python 3, there is still a lot of documentation (including examples) on the Web and in reference books that use Python 2, although more are being updated all the time. This can require some adjustment to make things work with Python 3 instead.

Some people just don’t want to use Python 3.x, which is their prerogative. However, they are in the minority.
It is worth noting that if you wish to use an alternative implementation of Python such as IronPython, Jython or Pyston (or one of the longer list of Python platform or compiler implementations), Python 3 support is still relatively rare. This may affect you if you are interested in choosing such an implementation for reasons of integration with other systems or for performance.

Thumbs Up

 

 

One thought on “Should I use Python 2 or Python 3 for my development activity?

  1. […] But what if you are starting a new project and have the choice to pick? I would say there is currently no “right” or “wrong” as long as both Python 2.7.x and Python 3.x support the libraries that you are planning to use. However, it is worthwhile to have a look at the major differences between those two most popular versions of Python to avoid common pitfalls when writing the code for either one of them, or if you are planning to port your project. After looking at the differences if you are still not able to decide then this post might help. […]

Comments are closed.