Which python versions you’re using ?

Many computers come with multiple python versions of the standard CPython runtime preinstalled. However, the default meaning of onpython the command-line may not be clear. python is usually an alias for,python2.7 but it can sometimes be an alias for older versions like python2.6 or python2.5 To find out exactly which version of Python youโ€™re using, you can use the flag --version.

>>> python --version
Python 2.7.8

Python 3 is usually available under the name python3.

>>> python3 --version
Python 3.6.1

You can also figure out the version of Python youโ€™re using at runtime by inspecting values in the sys built-in module.

>>> import sys
>>> print(sys.version_info)
>>> print(sys.version)
sys.version_info(major=3, minor=6, micro=1, releaselevel='final', serial=0)
3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:09:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

Python community actively maintains both Python 2 and Python 3. Development on Python 2 is frozen beyond bug fixes, security improvements, and backports to ease the transition from Python 2 to Python 3. Helpful tools like the 2 to 3 and six exist to make it easier to adopt Python 3 going forward.

Python 3 is constantly getting new features and improvements that will never be added to Python 2. Also, Python 2.7 is soon going to retire and will not be maintained past 2020 ย (refer pep-0373). So, I strongly encourage you to use Python 3 for your next Python project.

Take away from this post๐Ÿ“ฎ:

  • There are two major versions of Python still in active use: Python 2.x and Python 3.x.
  • We have multiple popular runtimes for Python: CPython, Jython, IronPython, PyPy, etc.
  • Be sure that the command-line for running Python on your system is the version you expect it to be.
  • Prefer Python 3 for your next project because that is the primary focus of the Python community and Python 2.7 support is soon going be come to an end of life.

Amit Baswa

Amit Baswa 1991 born professional web and applications developer with a degree of BSc in Information Technology. He started the blog Pythinks.com to help beginners and seekers in achieving most out of Python programming.