(Fixed) bash python command not found

Python is the powerful programming language in the current era that facilitates web development, artificial intelligence, and data science. Users may face a few errors while executing Python programs on Linux-based systems. One of them “bash python command not found” error, is displayed while executing the file through the terminal. This guide provides a solution to fix the above errors for possible reasons.

The content that illustrates this guideline is as follows:

Let’s start this guide with a reason and solution pattern.

Reason 1: Python Not Installed Properly

There is a possibility that Python might not be installed properly on your Linux system, which is the main reason causing this error. Here, a Python file named “program.py” is executed from the terminal:

$ python program.py

Doing so, an error stating the same reason, “bash python command not found”, is displayed.

Solution: Install Python

To encounter the above error is quite simple to install the python latest version from the built-in system repository. For this, the script is provided below for installing the latest “python3” version:

On Debian-Based Distributions:

$ sudo apt install python3

Finally, “python3” has been successfully installed in the Ubuntu operating system.

To display the current version of installed python is possible through the “– – version” utility:

$ python3 --version

The output shows that “Python 3.10.6” has been successfully installed in the current operating system.

It is extra information to install the latest version of Python in different operating systems. The syntax is provided as below:

Install Python on Fedora:

To install Python on Fedora operating system, execute the following script:

$ sudo dnf install python3

Install Python on RHEL/CentOS:

For installing Python on RHEL/CentOS, run the below command:

$ sudo yum install python3

Install Python on Arch Linux:

You can install python on Arch Linux by executing the below command:

$ sudo pacman -S python3

Reason 2: Path Not Configured

Another reason that causes the “bash python command not found” error is to be unable to access the configured file. It is because the machine locates the predefined directories to run the program properly.

Solution: Check the Python PATH Variable

To solve the accessibility problem of the Python path, execute the below script to check the python path variable:

$ type -a python3

Also you can also check the environment path variable by executing the below script:

$ echo $PATH

Note: Users can set the python directory by specifying the path by executing “export PATH=/usr/local/bin/python3” in the terminal.

Reason 3: Broken Softlink

The Softlink is a reference file, just like the shortcut in Windows Operating Systems. It points out only the name of the reference file rather than the hard drive location. If you utilize this link to a non-existent file, then it is said to be the broken soft link. In short, the error comes across if executable files are wrongly pointed.

Solution: Trace and Delete Softlink

To overcome the error, the “ls” utility can visualize the linked executable files. For this, execute the below script that traces the directory where the Python is installed:

$ ls -l /usr/bin/python3

The output shows the complete directory “/usr/local/bin/python3” where the Python is installed.

Remove the Symlink

After tracing the specific directory of python, remove the symlink by utilizing the “rm” command as below:

$ sudo rm /usr/bin.python3

That is all from this guide.

Conclusion

The “bash python command not found” error occurs when the python file cannot locate the system directory during execution. To resolve this error, you can reinstall the latest version of Python using the, configure the path of the python environment, and fix the soft link issue. Additionally, you can verify the installed python version through the “python –version” command. This article has explained all possible solutions with reasons for the “bash python command not found” error.