Seeing the “bash: python: command not found” error in Linux terminal is frustrating, especially when trying to run Python scripts or applications. This comprehensive guide explains what causes this error and the step-by-step methods for fixing it on any Linux distribution.
What Causes the “python: command not found” Error?
The “command not found” error occurs when the system is unable to locate the executable file for a program you are trying to run. There are two main reasons this happens with the python command:
1. Python is not installed
Python does not come pre-installed on Linux. The python command allows running the Python interpreter or scripts. If Python is not installed, bash cannot find the python executable file to launch it.
/usr/bin/python3 needs to be included in $PATH for the python command to work.
Step 3 – Add Python Path to $PATH
You can modify $PATH just for your current session:
However this change is lost when you close the terminal.
To make it permanent, add the path to your shell profile config file:
Bash – Add to ~/.bashrc:
Zsh – Add to ~/.zshrc:
Now source the file to update the current shell:
Python’s executable location is now permanently added to $PATH
Step 4 – Confirm with python Command
Finally, confirm Python can now be launched correctly:
The command should run successfully – python: command not found error resolved!
With this $PATH modification, all Python commands like python, pip, python3 etc will be accessible in Bash.
Method 3 – Create a Soft Link
An alternative to updating $PATH is to create a symbolic soft link to the python3 executable in a directory already in $PATH, like /usr/local/bin.
Step 1 – Create Soft Link
Run this command to symlink python3:
sudoln -s /usr/bin/python3 /usr/local/bin/python
This creates a virtual python soft link pointing to the real python3 executable.
Step 2 – Run Python Command
Now test running Python via the link:
With the link in /usr/local/bin present in $PATH, the python command maps to python3 and works normally.
This avoids modifying $PATH but achieves the same effect. Generally updating $PATH directly is the cleaner approach.
Troubleshooting Python Command Not Found Issues
If you still get “python: command not found” after the above steps, a few things to check:
Make sure Python is fully installed/updated before trying to run commands.
After adding python path to $PATH, source the shell config file (.bashrc/.zshrc) to update it.
Look for typos or errors in path added to $PATH – should match “which python3” output exactly.
If using a soft link, ensure /usr/local/bin is present in $PATH, otherwise link is not resolved.
Check for spaces or special characters in any added paths that could break commands.
On Debian/Ubuntu make sure both python and python3 packages are installed for 2.7 and 3.x commands.
Confirm exact case of the command – python vs Python vs PYTHON makes a difference.
Try closing terminal and opening a new shell session for $PATH changes to take effect.
Restarting the system can also flush out any inconsistencies causing issues.
Following this troubleshooting guide helps narrow down the cause and returns the python command up and running on any Linux distribution.
The “python: command not found” error occurs when the Linux shell is unable to locate the Python executable file to launch the command. Installing Python if missing and adding its path to the $PATH system variable are the key solutions discussed in detail.
Here is a summary of the main steps to permanently fix this error:
Check if Python is installed using the python3 –version command. If missing, install it through the OS package manager.
Find the path to the Python 3 executable returned by the which python3 command – usually /usr/bin/python3.
Add this /usr/bin/python3 path either temporarily or permanently to the $PATH variable in bash shell config files like ~/.bashrc.
Alternatively, create a soft symbolic link to python3 in a standard $PATH directory like /usr/local/bin.
Reload the shell or open a new terminal for $PATH changes to take effect.
Run python –version to confirm the command now launches Python successfully.
With Python accessible, you are ready to start running Python scripts and applications smoothly from the Linux terminal and integrate it into various workflows. Troubleshooting any further issues is also easier when the fundamentals of $PATH resolution are understood.
Greetings! I am Ahmad Raza, and I bring over 10 years of experience in the fascinating realm of operating systems. As an expert in this field, I am passionate about unraveling the complexities of Windows and Linux systems. Through WindowsCage.com, I aim to share my knowledge and practical solutions to various operating system issues. From essential command-line commands to advanced server management, my goal is to empower readers to navigate the digital landscape with confidence.
Join me on this exciting journey of exploration and learning at WindowsCage.com. Together, let’s conquer the challenges of operating systems and unlock their true potential.