How to Solve Python3 Command Not Found Error in Bash

Yahya Irmak Mar 11, 2025 Bash Bash Error
  1. Check if Python3 is Installed
  2. Add Python3 to Your PATH
  3. Create a Symlink for Python3
  4. Reinstall Python3
  5. Conclusion
  6. FAQ
How to Solve Python3 Command Not Found Error in Bash

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.

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

  1. 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.

  2. How can I check if Python3 is installed on my Linux system?
    You can check by running python3 --version in the terminal. If it returns a version number, Python3 is installed.

  1. 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.

  2. How do I add a directory to my PATH?
    You can add a directory by editing your shell configuration file (like .bashrc) and using the export PATH="$PATH:/new/directory" command.

  3. 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.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: Yahya Irmak
Yahya Irmak avatar Yahya Irmak avatar

Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.

LinkedIn

Related Article - Bash Error