Adventures in Machine Learning

Solving the Python was not found Error: Troubleshooting Guide

Troubleshooting “Python was not found; run without arguments to install from the Microsoft Store”

Python is an essential programming language that is widely used in many industries, including data science, web development, and automation. However, sometimes, you may encounter an error message that says, “Python was not found; run without arguments to install from the Microsoft Store.” This error message can be frustrating, especially if you are new to programming, and you don’t know how to solve it.

In this article, we will provide you with several solutions to troubleshoot this error, so you can get back to coding in no time.

1. Using the py alias instead of python

One of the reasons why you may encounter the “Python was not found” error is that you are using the wrong command. Instead of typing “python” in your terminal or command prompt, try using the “py” alias.

The “py” alias is a more convenient way of invoking Python, especially if you have multiple Python versions installed on your machine. For example, instead of typing “python my_script.py” in your command prompt, you can type “py my_script.py.” This will tell the system to use the default Python version installed on your machine.

2. Making sure your IDE is using the correct Python version

Another reason why you may encounter the “Python was not found” error is that your Integrated Development Environment (IDE) is not using the correct Python version. For example, if you have multiple Python versions installed on your machine, your IDE may be configured to use an older or non-existent version.

To fix this issue, you need to make sure that your IDE is using the correct Python version. For example, if you are using Visual Studio Code (VSCode), you can change the Python interpreter by selecting the appropriate version from the status bar.

3. Adding the path to Python and pip to your PATH environment variable

If you have installed Python and pip (the Python package manager) in a non-default location, you may encounter the “Python was not found” error. To fix this issue, you need to add the path to Python and pip to your PATH environment variable.

The PATH environment variable is a list of directories that the system searches when looking for executable files. By adding the path to Python and pip to your PATH environment variable, you are telling the system where to find these programs.

To add the path to Python and pip to your PATH environment variable, follow these steps:

  1. Open the Start menu and search for “Environment Variables”
  2. Click on “Edit the system environment variables”
  3. Click on the “Environment Variables” button
  4. Under “System Variables,” scroll down until you find the “Path” variable and select it
  5. Click on “Edit”
  6. Click on “New” and enter the path to the directory containing the Python executable and pip executable (e.g., C:Python38;C:Python38Scripts)
  7. Click “OK” on all windows to save changes

4. Disabling the Python App installer in “App execution aliases”

If you have recently installed Python from the Microsoft Store, you may encounter the “Python was not found” error.

This is because the Python executable is installed in a different location, and the system is not aware of it. To fix this issue, you need to disable the Python App installer in “App execution aliases.”

To disable the Python App installer, follow these steps:

  1. Open the Start menu and search for “Apps & features”
  2. Scroll down and find “Python”
  3. Click on “Advanced options”
  4. Under “App execution aliases,” toggle off “Python” and “Python Launcher”
  5. Close the settings window

5. Adding Python to your PATH using the official installer

If you have installed Python using the official installer, you may still encounter the “Python was not found” error. This is because the installer may not have added Python to your PATH environment variable.

To add Python to your PATH using the official installer, follow these steps:

  1. Download the latest version of Python from the official website (https://www.python.org/downloads/)
  2. Run the installer and select “Customize installation”
  3. Make sure that “Add Python to PATH” is checked
  4. Click “Install now” to start the installation process

6. Restarting your PC to make sure you don’t have stale IDE and shell sessions

If none of the solutions above work, consider restarting your PC. Sometimes, your IDE or command prompt may have a stale session that is preventing it from finding Python.

By restarting your PC, you will clear any stale sessions, and start fresh. This may solve the “Python was not found” error, and you can get back to coding.

Additional Resources

In addition to the solutions provided above, there are several resources on the web that can help you troubleshoot the “Python was not found” error. Here are a few:

Conclusion

In conclusion, the “Python was not found” error can be frustrating, but it is not insurmountable. By following the solutions provided above, you can troubleshoot this error and get back to coding in no time.

Remember to use the “py” alias, make sure your IDE is using the correct Python version, add the path to Python and pip to your PATH environment variable, disable the Python App installer, add Python to your PATH using the official installer, and restart your PC if necessary. With these solutions, you can continue to use Python and take advantage of its power and versatility.

In summary, encountering the “Python was not found” error message can be frustrating, but it’s not an insurmountable challenge. To overcome this error, one can utilize the py alias, make sure the IDE is using the correct Python version, add the path to Python and pip to the PATH environment variable, disable the Python App installer, add Python to PATH using the official installer, and restart the PC if necessary.

It’s crucial to remember these solutions to continue utilizing the language’s power and versatility. If you encounter the same error message again, don’t panic, and consider revisiting the strategies mentioned here.

Popular Posts