How To Check If Python Is Installed On Linux : Confirming Python Installation Path

To verify Python on a Linux system, type `python –version` or `python3 –version` to see if the interpreter responds. This quick command is the most reliable way to check if Python is installed. Knowing How To Check If Python Is Installed On Linux is essential before you start any development or scripting project.

Many Linux distributions come with Python pre-installed, but the version can vary. You might need to check for Python 2, Python 3, or both. This article walks you through every method, from simple terminal commands to verifying package managers.

How To Check If Python Is Installed On Linux

Let’s start with the most direct approach. Open your terminal emulator—usually found in your applications menu or by pressing Ctrl+Alt+T. Once the terminal is open, you can run a few simple commands.

Using The Python Version Command

The fastest way is to ask the Python interpreter to report its version. Type one of these commands:

  • python --version
  • python -V
  • python3 --version
  • python3 -V

If Python is installed, you’ll see output like Python 3.10.12 or Python 2.7.18. If it’s not installed, you’ll get an error message like command not found: python.

On newer Linux distributions, only python3 is available by default. The python command might point to Python 2 or might not exist at all. Always try both commands to be thorough.

Checking For Python 2 And Python 3 Separately

Some systems have both versions installed. Run these commands individually:

  1. python2 --version (checks for Python 2)
  2. python3 --version (checks for Python 3)

If you see version numbers for both, you have dual installations. If one returns an error, that specific version is missing. This is common on older systems still using Python 2 for legacy scripts.

Using The Which Command To Locate Python

The which command shows you the exact path of the Python executable. This confirms not only that Python is installed, but also where it lives on your system.

Type: which python or which python3

If Python is installed, you’ll see output like /usr/bin/python3 or /usr/local/bin/python. If nothing appears, Python is not in your PATH, which usually means it’s not installed.

You can also use whereis python to find all Python-related files, including binaries, source code, and man pages. This gives you a broader view of what’s available.

What If Which Returns Nothing?

If which python returns no output, don’t panic. Python might be installed but not in your user’s PATH. Try the version commands first, as they are more direct. If those also fail, Python is likely not installed.

Checking Python Through Package Managers

Linux package managers can tell you if Python is installed and what version. Each distribution uses a different manager, but the logic is similar.

For Debian And Ubuntu (APT)

Run: apt list --installed | grep python

This lists all installed packages containing “python” in their name. You’ll see entries like python3/stable or python2.7/stable. If nothing appears, Python isn’t installed via APT.

You can also check with: dpkg -l | grep python

For Red Hat, Fedora, And CentOS (YUM Or DNF)

On older systems: yum list installed | grep python

On newer systems: dnf list installed | grep python

These commands show all Python-related RPM packages. If you see python3.x86_64, you’re good. If not, Python needs to be installed.

For Arch Linux (Pacman)

Run: pacman -Q | grep python

This queries all installed packages and filters for Python. Output looks like python 3.11.5-1. An empty result means Python is missing.

For OpenSUSE (Zypper)

Use: zypper search --installed-only python

This lists installed Python packages. If nothing shows, Python isn’t installed via Zypper.

Using The Type Command As An Alternative

The type command is built into Bash and works similarly to which. It tells you how a command would be interpreted.

Type: type python or type python3

If Python is installed, you’ll see: python is /usr/bin/python or python is hashed (/usr/bin/python). If it’s not found, you’ll get: bash: type: python: not found.

This method is slightly more reliable than which because it checks the shell’s internal command cache.

Checking Python Version With A One-Liner Script

You can also write a tiny Python script to confirm installation. This is useful if you want to verify that Python can actually execute code, not just that the binary exists.

Create a file called check.py with this content:

import sys
print(f"Python version: {sys.version}")

Then run: python3 check.py

If Python works, you’ll see the full version string. If not, you’ll get an error. This method is overkill for simple checks but can be helpful in automated scripts.

What If Python Is Not Installed?

If all checks fail, Python is not on your system. Don’t worry—installing it is straightforward. Here’s how to install Python on major distributions.

Installing Python On Ubuntu Or Debian

Update your package list and install Python 3:

  1. sudo apt update
  2. sudo apt install python3

You can also install the python3-pip package for package management.

Installing Python On Fedora Or CentOS

For Fedora: sudo dnf install python3

For CentOS 7: sudo yum install python3

For CentOS 8+: sudo dnf install python3

Installing Python On Arch Linux

Run: sudo pacman -S python

This installs the latest Python 3 version available in the repositories.

Installing Python On OpenSUSE

Use: sudo zypper install python3

After installation, verify with python3 --version to confirm success.

Common Issues When Checking Python Installation

Sometimes the commands work but give unexpected results. Here are typical problems and solutions.

Python Command Points To Wrong Version

On some systems, python might point to Python 2 even if Python 3 is installed. Always use python3 explicitly to avoid confusion. You can check the symlink with ls -l /usr/bin/python.

Multiple Python Versions Installed

You might have Python 3.8, 3.9, and 3.10 all installed. Use python3.8 --version, python3.9 --version, etc., to check each. The python3 command usually points to the default version.

Python Installed But Not In PATH

If Python is installed in a custom location like /opt/python/bin, it won’t be found by default. Add it to your PATH by editing ~/.bashrc or ~/.profile. Add this line: export PATH="/opt/python/bin:$PATH".

Permission Denied Errors

If you get “Permission denied” when running Python, the executable might not have execute permissions. Fix with: sudo chmod +x /usr/bin/python3. This is rare but can happen after manual installations.

Using Python’s Built-In Help System

Once you confirm Python is installed, you can use its help system to get more details. Run python3 -c "import sys; print(sys.executable)" to see the exact binary path.

You can also check the Python installation directory with: python3 -c "import sys; print(sys.prefix)"

This shows where Python’s libraries are stored, which is useful for debugging.

Automating The Check With A Shell Script

If you need to check Python installation repeatedly, write a small shell script. Here’s a simple example:

#!/bin/bash
if command -v python3 &>/dev/null; then
    echo "Python 3 is installed"
    python3 --version
else
    echo "Python 3 is not installed"
fi

Save this as check_python.sh, make it executable with chmod +x check_python.sh, and run it with ./check_python.sh. This script uses command -v to check if the executable exists.

Checking Python In Virtual Environments

If you use virtual environments, Python might be installed globally but not activated. Always activate your virtual environment first with source venv/bin/activate, then run python --version. The version shown will be the one inside the environment.

To check if a virtual environment exists without activating it, look for the bin/python file inside the environment directory. Run: ls -l venv/bin/python.

Using The LSB (Linux Standard Base) Tools

Some systems have the lsb_release command, which can show installed packages. Run: lsb_release -a to see distribution info, but this doesn’t directly check Python. It’s more useful for context.

You can combine it with other commands: lsb_release -d && python3 --version to see both distro and Python version in one line.

Graphical Methods To Check Python

If you prefer not to use the terminal, you can check Python installation through your system’s package manager GUI. On Ubuntu, open “Ubuntu Software” and search for “python”. If it’s installed, you’ll see a “Remove” button. On Fedora, use “Software” app similarly.

However, the terminal method is faster and more reliable. The GUI might not show all Python versions or custom installations.

Checking Python Documentation

Once Python is confirmed, you can check its documentation locally. Run python3 -c "import this" to see the Zen of Python, which proves the interpreter works. Or run pydoc3 to start the documentation browser.

These commands are not installation checks but confirm that Python is fully functional.

Frequently Asked Questions

How Do I Check If Python Is Installed On Linux Without Terminal?

You can use your system’s package manager GUI. On Ubuntu, open “Ubuntu Software” and search for Python. On Fedora, use the “Software” app. However, the terminal method with python3 --version is more reliable and works on all distributions.

What Command Checks Python Version In Linux?

The commands are python --version, python -V, python3 --version, and python3 -V. All four work similarly. Use python3 on modern systems to ensure you’re checking Python 3.

Why Does ‘Python’ Not Work But ‘Python3’ Does?

Many modern Linux distributions only install Python 3 by default and don’t create a python symlink. This is intentional to avoid confusion with Python 2. Always use python3 unless you specifically need Python 2.

Can I Check Python Installation Using A Script?

Yes, you can write a shell script using command -v python3 or a Python script that imports sys and prints the version. Both methods work well for automation and CI/CD pipelines.

What If Python Is Installed But Not Found In PATH?

Add the Python binary directory to your PATH variable. Edit ~/.bashrc or ~/.profile and add export PATH="/path/to/python/bin:$PATH". Then reload with source ~/.bashrc.

Final Thoughts On Checking Python Installation

Knowing How To Check If Python Is Installed On Linux is a fundamental skill for any developer or system administrator. The methods covered here—from simple version commands to package manager queries—give you multiple ways to verify Python’s presence.

Always start with python3 --version as your primary check. If that fails, try the package manager approach. Remember that Python 2 is deprecated, so focus on Python 3 for new projects.

If you encounter any issues, refer to the common problems section. Most errors are due to missing symlinks or PATH configuration. With these techniques, you can confidently manage Python installations on any Linux system.