How to check Python version in Ubuntu
How to Check the Python Version in Ubuntu
In the Ubuntu operating system, there are several ways to check the installed Python version. The following describes three common methods.
Method 1: Check via the command line
Enter the following command in the terminal to check the installed Python version:
python --version
Or
python3 --version
These two commands are used to check the version of Python installed on your system:
python --version
Or
python3 --version
These two commands are used to check the version of Python installed on your system:
href=”https://geek-docs.com/python/python-top-tutorials/1000100_python_index.html” rel=”noopener” target=”_blank” title=”Python Tutorial”>Python 2 and Python 3 versions. For example, typing python --version
will display information similar to the following:
Python 2.7.17
Try typing python3 --version
will display information similar to the following:
Python 3.8.5
Method 2: Viewing Installed Python Packages
Another method is to view the installed Python packages and their corresponding versions. You can use the following command to list all installed Python packages and their versions:
pip list
If pip is not installed, you can first install it:
sudo apt install python3-pip
Then run the pip list
command.
Method 3: Check with a Python Script
You can also check the Python version by writing a simple Python script. Create a new Python file, such as check_python_version.py
, and enter the following:
import sys
print(sys.version)
<p>Then run the script in the terminal:
<pre><code class="language-bash line-numbers">python check_python_version.py
Or
python3 check_python_version.py
This will output the Python version information installed on your system.
These are three common ways to check the Python version in Ubuntu. You can easily obtain Python version information through the command line, by checking installed Python packages, or by writing a Python script.