Every program consists of some variables and constant values. As the name suggests, we have environment variables that define the environment for some applications.
Several such variables are available, and we can also define our environment variables.
One such variable is
PATH, which contains a list of directories containing all the executable files used to run some commands. Before using Python, we need to install it and add the directory of its executable to the
This ensures that we can run the Python command from the command prompt.
This tutorial will discuss the
Can't find Python executable "python", you can set the PYTHON env variable error in Python and how to fix it.
Error: Can't find Python executable "python", you can set the PYTHON env variable in Python
This error can persist when an application cannot find the location of the Python executable file. We need to ensure that the full path of the
python.exe file has been added to the environment variable.
For Windows, we can check this by following the steps discussed below.
First, we must right-click
This PC and select the
Properties option from the menu. Then we need to go to the
Advanced Settings menu and select
This will take us to the
Environment Variable screen, where we need to add the directory of the Python executable.
We need to add the directory to the
PATH variable for the
User. If the error persists, we can create a new variable named
Python and add the directory here.
This should usually remove the discussed error.
Another common situation where this error can be expected is while installing Node.js and NPM on Windows. For such situations, there are further few more fixes that can help.
The first fix is using Microsoft
windows-build-tools to install any required tools. We can use the following command in the command prompt.
npm install -g windows-build-tools
However, this will install some versions of Python in a new environment.
We can also configure the path of the Python executable with the
npm config command. It can assist in some cases.
Use it as shown below.
npm config set python C:\Dir\Python\Python27\python.exe