How to Solve Python3 Command Not Found Error in Bash
- Check if Python3 is Installed
- Add Python3 to Your PATH
- Create a Symlink for Python3
- Reinstall Python3
- Conclusion
- FAQ

When you’re working in a Linux environment, encountering the “python3: command not found” error can be frustrating. This issue typically arises when the Python 3 interpreter isn’t installed, or the system can’t find the executable in its PATH. Whether you’re a developer, a data scientist, or just a tech enthusiast, knowing how to troubleshoot this error is essential.
In this article, we’ll explore various methods to resolve the Python3 command not found error in Bash, ensuring you can get back to coding without a hitch. Let’s dive in!
Check if Python3 is Installed
The first step in solving the “command not found” error is to check if Python3 is indeed installed on your system. Open your terminal and run the following command:
python3 --version
This command attempts to retrieve the version of Python3 installed on your machine. If Python3 is installed, you’ll see an output similar to:
Python 3.x.x
If you receive an error message stating that the command is not found, it indicates that Python3 is either not installed or not accessible from your current terminal session.
To install Python3 on a Debian-based system, use:
sudo apt update
sudo apt install python3
For Red Hat-based systems, the command is:
sudo yum install python3
After installation, run the version command again to confirm the installation was successful.
Output:
Python 3.x.x
By verifying whether Python3 is installed, you can quickly identify if the issue is with the installation or something else entirely.
Add Python3 to Your PATH
If Python3 is installed but you still encounter the command not found error, the next step is to check your system’s PATH variable. The PATH variable tells your system where to look for executable files. If Python3’s installation directory isn’t included in this variable, Bash won’t be able to find it.
To check your current PATH, run:
echo $PATH
You should see a list of directories separated by colons. If the directory containing the Python3 executable (usually /usr/bin
or /usr/local/bin
) is missing, you will need to add it. You can do this by editing your shell configuration file, like .bashrc
or .bash_profile
.
Open the file in a text editor:
nano ~/.bashrc
Add the following line at the end of the file:
export PATH="$PATH:/usr/bin"
Save and exit the editor. Then, refresh your terminal session by running:
source ~/.bashrc
Now, try checking the Python3 version again.
Output:
Python 3.x.x
By ensuring that the directory containing the Python3 executable is in your PATH, you can resolve the command not found error effectively.
Create a Symlink for Python3
Sometimes, the Python3 command might not be linked to the correct executable. In this case, creating a symbolic link can help. A symlink is a pointer that directs a command to the actual executable file.
First, check where Python3 is installed by running:
which python3
If this command returns a path, you can create a symlink to ensure that Bash recognizes it. If it returns nothing, you may need to install Python3 first.
To create a symlink, use the following command:
sudo ln -s /usr/bin/python3 /usr/local/bin/python3
This command creates a symbolic link in /usr/local/bin
pointing to the Python3 executable. Now, try running:
python3 --version
Output:
Python 3.x.x
Creating a symlink is a straightforward way to ensure that the command is recognized, especially if the executable is located in a non-standard directory.
Reinstall Python3
If you’ve tried the previous methods and are still facing the “command not found” error, it might be time to consider reinstalling Python3. Sometimes, installations can become corrupted or incomplete, leading to issues.
To reinstall Python3, first, remove the existing installation:
sudo apt remove python3
Then, clean up any residual configuration files:
sudo apt autoremove
Now, you can reinstall Python3:
sudo apt update
sudo apt install python3
After the installation completes, verify it by checking the version again:
python3 --version
Output:
Python 3.x.x
Reinstalling Python3 can resolve underlying issues that might be causing the command not found error, ensuring a fresh and functional setup.
Conclusion
Encountering the “python3: command not found” error in Bash can be a nuisance, but it’s usually straightforward to resolve. By checking if Python3 is installed, ensuring it’s in your PATH, creating a symlink, or even reinstalling it, you can get back to your coding tasks in no time. Remember that troubleshooting is a skill that improves with practice, and understanding how to manage your environment will make you a more efficient developer. Happy coding!
FAQ
-
What does the “command not found” error mean?
The error indicates that the system cannot locate the specified command, often because the executable is not installed or not in the PATH. -
How can I check if Python3 is installed on my Linux system?
You can check by runningpython3 --version
in the terminal. If it returns a version number, Python3 is installed.
-
What should I do if Python3 is installed but still shows a command not found error?
Check your PATH variable to ensure the directory containing the Python3 executable is included. -
How do I add a directory to my PATH?
You can add a directory by editing your shell configuration file (like.bashrc
) and using theexport PATH="$PATH:/new/directory"
command. -
Is it necessary to create a symlink for Python3?
Creating a symlink is not always necessary, but it can help if the command is not pointing to the correct executable.
Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.
LinkedIn