0

Before adding python executable path to the System PATH environment variable, python command does not work in visual studio code terminal, and the following error shows up:

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

However, when the python executable path is added to the system PATH environment variables, the terminal works fine when i enter the python command.

Terminal showing current directory:
Terminal showing current directory

What confused me is - since the current directory the VS code terminal is showing is the user directory i.e C:\Users\user_name, why doesnt VS code just look into the User PATH environment variables for the python executable (which i have already included in)?

starball
  • 20,030
  • 7
  • 43
  • 238
Jackson
  • 17
  • 4

1 Answers1

0

Windows comes with dummy python executables python.exe and python3.exe that take you to the microsoft store to install it- after which it is a real python executable instead of a dummy one. If you run where python, you'll get a list of all the python executables that are found via the PATH variable in the order that they are found in the PATH, where one of them will be the Windows one (instead of the one you installed from the Python website). The one you'll see listed first will probably be C:\Users\you\AppDate\Local\Microsoft\WindowsApps\python.exe (or something like that). (see related question: Why can't I run python in git bash and visual studio code?)

The behaviour you're observing is due to the fact that Windows searches the PATH from left to right / first to last (see related question: What's the relative order with which Windows search for executable files in PATH?), and the combined PATH formed from the system PATH and user PATH puts the system PATH before the user PATH (see related question: User vs. System Environment Variables: Do System Variables Override User Variables?).

Another approach would be to just remove those dummy executables in your Windows "App Executable Alias" settings (as shown in this answer).

starball
  • 20,030
  • 7
  • 43
  • 238