How To Fix Python Was Not Found

If you’re trying to install Python or run a Python script and see the error message “Python was not found,” don’t worry! This is a common issue, and we can help you fix it. This error could be caused by a few different problems, such as Python not being installed, the PATH variable not being set correctly, or using the wrong command to run Python. In this blog post, we’ll walk you through how to diagnose and fix the “Python was not found” error.

1. Check if Python is installed

The first step is to check if Python is installed on your system. To do this, open a terminal or command prompt and type the following command:

        python --version
    

If Python is installed, this command should display the Python version number. If you see an error message instead, proceed to the next step to install Python.

2. Install Python

If Python is not installed, visit the official Python website (https://www.python.org/downloads/) and download the latest version of Python for your operating system. Follow the installation instructions provided on the website or in the downloaded installation file. Make sure to check the Add Python to PATH option during the installation process. This will ensure that Python is added to your system’s PATH variable, which we’ll discuss in more detail in the next step.

3. Check the PATH variable

The PATH variable is an environment variable that tells your computer where to look for executable programs like Python. If Python is installed but not added to the PATH variable, you’ll get the “Python was not found” error.
To check your PATH variable, follow these instructions for your specific operating system:

Windows:

  1. Open the Start menu and search for “Environment Variables.”
  2. Click on “Edit the system environment variables.”
  3. In the “System Properties” window, click on “Environment Variables.”
  4. Look for “Path” in the “System variables” section and click on “Edit.”
  5. Make sure the Python installation path is included in the list of paths. The typical Python installation paths are: C:Python or C:Users<YourUsername>AppDataLocalProgramsPythonPythonxx (where “xx” is the Python version).
  6. If it’s not there, add it and click “OK.”

macOS and Linux:

  1. Open a terminal.
  2. Type the following command: echo $PATH
  3. Ensure that the Python installation path is included in the output. The typical Python installation paths for macOS and Linux are /usr/local/bin/python or /usr/bin/python.
  4. If it’s not there, update the PATH variable by adding the following line to your .bashrc or .bash_profile file: export PATH=$PATH:/path/to/python (replace “/path/to/python” with the actual Python installation path).

4. Use the correct command to run Python

Lastly, ensure you’re using the proper command for running Python. Simple mistakes like typing “python” instead of “python3” or vice versa can cause the “Python was not found” error. Check the installed version of Python on your computer by running python --version or python3 --version and use the appropriate command accordingly.

Conclusion

By following these steps, you should be able to resolve the “Python was not found” error and start running Python scripts with ease. Remember to check if Python is installed, ensure it’s added to your system’s PATH variable, and use the correct command to run Python. Happy coding!