Check Python version
How To

How to Check Python Version in Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

Want to check the Python version in Ubuntu? The easiest way to do so is to use the following command:

python3 --version
How to check python version in Ubuntu

Yep, that's all it takes to check the Python version.

But if you are using Python 2 (deprecated and no longer shipped with the recent edition of Ubuntu), you can use the following command:

python --version
Check the installed verion of Python for Python 2 in Ubuntu

Want more details? I got you!

How to check the Python version in Ubuntu

No, you don't need to install Python in Ubuntu and the reason is quite simple.

It comes pre-installed in every Linux distribution as Python is an integral part of the Linux kernel now and many system utilities heavily rely on Python.

Sure, you can update the Python to a newer version when available but that's all you can do!

While there are multiple possibilities of how you find the Python version in Ubuntu, I will walk you through two ways to do so:

  • Using the python command
  • Using python interactive shell

So let's start with the first one.

Using the python command

This is what I explained at the beginning of this guide.

If you don't know, you are given a pyhon command in Linux which you can use to write code. But it can also be used to check the version of python.

As most Linux distribution has ditched Python 2 (Ubuntu has been shipping Python3 since Ubuntu 20.04), most of your systems are running Python 3.

And here's how you can check the version of Python 3 in Ubuntu:

python3 --version
check python 3 version in Ubuntu

As you can see, I'm running Python 3.10.12.

But if you are running Python 2 (somehow) and want to know what version you are running, then here's how you do it:

python --version
check python 2 version in Ubuntu

Pretty easy. Right?

Using the python interactive shell

This method also utilizes the python command but uses an interactive shell to fetch the installed version.

For Python 2:

python -c "import sys; print(sys.version)"
Check the installed version of Python 2 using interactive shell in Ubuntu

The above output indicates I'm running Python 2.7.6.

For Python 3:

python3 -c "import sys; print(sys.version)"
Check the installed version of Python 3 using interactive shell in Ubuntu

That's it!

More on Python

Here's how to install pip3 on Ubuntu:

How to Install pip3 on Ubuntu
Pip is a handy command line utility for installing Python packages. Learn how to install and use Pip3 on Ubuntu.

Want to upgrade Python on Ubuntu? Here's a detailed guide explaining how to upgrade Python on Ubuntu:

Install and Upgrade Python on Ubuntu Command Line
Learn how you can install Python version of your choice in Ubuntu or upgrade to a newer version.

I hope you will find this guide helpful.



Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.