How to Resolve Python Command Not Found Error in Linux
Last Updated :
24 Sep, 2024
Python is a powerful programming language commonly used for various tasks, ranging from scripting to web development and data analysis. However, when working with Python on a Linux system, you may encounter the frustrating "Python command not found" error. This error occurs when the system cannot locate the Python interpreter, preventing you from running Python scripts or accessing the Python REPL (Read-Eval-Print Loop).
In this article, we'll explore various scenarios that can lead to this error and provide step-by-step solutions to resolve it.
Verify Python Installation
The first step in resolving the "Python command not found" error is to verify whether Python is installed on your system. Open a terminal and execute the following command:
python --version
Checking if python is installed or notIf Python is installed, this command will display the installed Python version. If you see an error message such as "command not found," it indicates that Python is not installed or is not accessible from the current shell session.
Check the PATH Environment Variable
In Linux, the Python interpreter is typically installed in the '/usr/bin' directory. To ensure that the Python executable is included in the system's PATH environment variable, execute the following command:
echo $PATH
If '/usr/bin' is not included in the output, you need to add it to the PATH variable. You can do this by modifying your shell configuration file (e.g.,'.bashrc', '.bash_profile', '.zshrc', etc.) and appending the following line:
export PATH="/usr/bin:$PATH"
After making the changes, reload the shell configuration file by running:
source ~/.bashrc
How to Resolve Python Command Not Found Error in Linux
Here is the most common error that users face when they try to run python command , or python3 command.
Python command not foundInstall Python to avoid Python Command Not Found Error in Linux
If Python is not installed on your system, you can install it using your distribution's package manager. For example, on Debian-based systems like Ubuntu, you can use the following command:
sudo apt update
sudo apt install python3
Note: If you are unable to install python from command line, so you have to download it manually from official site.

Click on "Download Python 3.12.2". Open Command Line and go to the downloads folder, where you will find "Python-3.12.2.tar.xz"

Then we have to download the "Python-3.12.2" file. For this we have to enter the "Python-3.12.2" directory
cd Python-3.12.2
Run the configuration script, optionally specifying installation location (e.g., use /usr/local to avoid system-wide conflicts)
./configure --enable-optimizations --prefix=/usr/local
Build Python
make -j $(nproc) # Use all available cores
Install Python
sudo make altinstall # Install without overwriting system Python
Verify Python
python3.12 --version
Install Python From Terminal in linux
To install Python on Linux from the terminal, you can use the package manager specific to your distribution. Here are the commands for some popular distributions:
Installing in Ubuntu/Debain:
sudo apt update
sudo apt install python3
installing python in linuxInstalling in Fedora:
sudo dnf install python3
Installing in CentOS:
sudo yum install python3
Installing in Arch Linux:
sudo pacman -S python
Replace python3
with python
in the commands if you specifically need Python 2.
Note: Python 2 is no longer supported and you should use Python 3 for new projects.
Conclusion
In conclusion, resolving the "Python Command Not Found" error in Linux involves checking whether Python is installed, verifying the Python executable's path in the system's PATH variable, and installing Python if necessary. By following these steps and users can effectively address the error and ensure Python is correctly configured on their Linux system.
Similar Reads
How to Resolve npm Command Not Found Error in Node.js
Node Package Manager (npm) is the default package manager for NodeJS. It allows developers to easily manage libraries and dependencies in their NodeJS projects. It is an essential tool for managing the installation and versioning of packages from the npm registry.The npm: command not found error hap
4 min read
How to Fix "pip command not found" in Linux
Python has become an essential tool for developers, data scientists, and system administrators due to its versatility and extensive libraries. The 'pip' tool, which is the standard package manager for Python, plays a crucial role in managing Python packages, libraries, and dependencies. However, enc
9 min read
How to fix Bash: Command Not Found Error in Linux
The "command not found" error is a frequently encountered issue in Linux systems. This error occurs when the system is unable to locate the file specified in the path variable. This error typically occurs when the system cannot locate the command in the directories specified by the path variable.Wha
6 min read
How To Fix: Sudo npm: Command not Found on Linux
"npm: Command not Found" is one of the most basic errors we face while getting started with Javascript. We may get this error while installing the node package manager. Node and npm packages are not related to nodejs and therefore not included in the nodejs package. NPM stands for Node Package Manag
2 min read
How To Fix "Bash: Docker: Command Not Found" In Linux
Docker has become an essential tool for developers and system administrators to manage and deploy applications efficiently. However, encountering the error message "Bash: Docker: Command Not Found" can be frustrating, especially when you're trying to work with Docker containers. Here, we'll explore
4 min read
How to Fix apt-get command not found in Linux
Linux, celebrated for its power and versatility, can occasionally pose challenges, especially for newcomers. The apt-get command, a vital tool for package management in Debian-based Linux distributions like Ubuntu, is essential for installing, updating, and managing software. However, you may encoun
5 min read
Run function from the command line In Python
Python is a flexible programming language with a wide range of uses that one of Pythonâs most useful ones is its ability to execute functions from the command line. Especially this feature is very useful when it comes to automation and scripting etc. In this article, Iâll explain how to execute a Py
4 min read
How to fix - "EnvironmentError: mysql_config not found" in Python
The "EnvironmentError: mysql_config not found" problem is frequently encountered by Python developers, especially when working with MySQL databases. It occurs when the Python interpreter is unable to find the MySQL configuration file (mysql_config) required for creating particular Python modules or
3 min read
"How to Fix 'jupyter: command not found' Error After Installing with pip "
Encountering the "Jupyter command not found" error after installing Jupyter with pip can be frustrating. This common issue typically arises due to problems with the installation path or virtual environments. In this guide, we'll explore the root causes and provide step-by-step solutions to fix this
4 min read
How to Fix the Invalid Argument Error on Linux
If you have ever run a Linux command in your system terminal and seen the Invalid Argument error, there could be a few reasons for this. It usually means that you used an argument (a special word or setting) that the command doesn't recognize, or your user account doesn't have permission to access t
5 min read