Why 'Python was not found' error message is displayed by the command prompt when attempting to execute a Python script?
Issue Description:
While setting up a Process Mining App using APP templates (for instance Coupa Purchase-to-Pay App Template), upon executing the Python script from the Command Prompt, an error message "Python was not found" is displayed on the command prompt. This issue persists despite Python being already installed on the machine.
An example of such a situation might be executing the following command:
C:\Users\[xxxxxx]\Downloads\coupa_p2p_extractor>python coupa_p2p_extractor.py.
Upon execution, an error as shown below is displayed:
Root Cause:
The issue stems from the system's PATH variable which includes directories for the command prompt to scan for commands. If Python is installed from the official site but does not add Python to your PATH, the command prompt cannot access python.exe. In contrast, the Microsoft Store version automatically adds Python to the PATH, making it available system-wide. Therefore, it's recommended to install Python from the official site and opt to 'Add Python to PATH'.
Resolution:
Approach #1: Install Python from Microsoft Store
- Open the Command Prompt and attempt to run the Python command.
- For example: C:\Users\[xxxxxx]\Downloads\coupa_p2p_extractor>python.
- Upon executing the command, it will redirect us to the Microsoft Store page here.
- Even if Python is previously installed on the machine, download and install the Python App from the Microsoft Store.
- After the installation is complete, re-run the original command(i.e. C:\Users\[xxxxxx]\Downloads\coupa_p2p_extractor>python coupa_p2p_extractor.py) and "Python was not found" error message is not encountered anymore.
Approach #2: Manually Update System Path for Python after installing it from the Official site.
- Find out where Python got installed on the system. On many systems, it's typically in C:\Python39\ or C:\Users\[YourUsername]\AppData\Local\Programs\Python\Python39\, replacing '39' with the version installed.
- Copy that path to the clipboard.
- Add the path to the system’s Environment Variables.
- Press Windows + X and select 'System'. Click on 'System info' at the right top side. This will open the 'System Properties' window.
- Click on 'Advanced System Settings'.
- In the 'System Properties' window that appears, on the 'Advanced' tab, click on the 'Environment Variables' button.
- This will present a set of options: 'User variables' and 'System variables'. 'System variables' are available to all users on the machine.
- Scroll down the 'System variables' to find the variable named 'Path'. Select it, then click on 'Edit'.
- A list of all the locations available in the Path variable appears.
- Click on 'New', and then paste the Python path that was copied earlier.
- Click 'OK', then 'OK' again in the previous windows.
Approach #3: Uninstall and reinstall Python with System Path
By following these steps, the issue should be resolved and Python scripts should execute without any problems from the Command Prompt.