How to Check Python Version in Ubuntu
Learn how to quickly check the current Python version in use in Ubuntu Linux.
Want to check the Python version in Ubuntu? The easiest way to do so is to use the following command:
python3 --version
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
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
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
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)"
The above output indicates I'm running Python 2.7.6.
For Python 3:
python3 -c "import sys; print(sys.version)"
That's it!
More on Python
Here's how to install pip3 on Ubuntu:
Want to upgrade Python on Ubuntu? Here's a detailed guide explaining how to upgrade Python on Ubuntu:
I hope you will find this guide helpful.
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.