Error: Can't Find Python Executable Python, You Can Set the PYTHON Env Variable
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 PATH
variable.
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.
the 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 Environment Variables
.
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
Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.
LinkedInRelated Article - Python Error
- Can Only Concatenate List (Not Int) to List in Python
- How to Fix Value Error Need More Than One Value to Unpack in Python
- How to Fix ValueError Arrays Must All Be the Same Length in Python
- Invalid Syntax in Python
- How to Fix the TypeError: Object of Type 'Int64' Is Not JSON Serializable
- How to Fix the TypeError: 'float' Object Cannot Be Interpreted as an Integer in Python