-bash: python: command not found error and solution

The “command not found” error message you’re encountering indicates that the python command is not recognized by your shell because it is not in your shell’s PATH.

Here are some steps you can take to resolve this issue:

  1. Check if Python is installed:
python3 --version

If Python is installed, the above command will display the version of Python installed on your system. If Python is not installed, you’ll need to install it.

  1. Add the Python executable to your PATH:

You can add the Python executable to your PATH by editing your shell profile file (e.g., ~/.bashrc, ~/.bash_profile, or ~/.profile) and adding the following line:

export PATH=$PATH:/usr/bin/python3
  1. Restart your shell:

After adding the above line to your profile file, you need to restart your shell to pick up the changes:

exec $SHELL

After these steps, the python command should be recognized by your shell, and you should no longer encounter the “command not found” error.

Leave a Comment