CMD opens Windows Store when I type 'python'
Question:
Today when I tried to run simple code on Sublime Text 3, the following message appeared:
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
And when I type Python in CMD, it opens the Windows Store for me to download Python 3.7. This problem started today for no good reason. I didn’t change or download anything about Python and already tried reinstalling Python, and the Path environment variable is correct.
Answers:
Use the Windows search bar to find "Manage app execution aliases". There should be two aliases for Python. Unselect them, and this will allow the usual Python aliases "python" and "python3". See the image below.
I think we have this problem when installing Python because in a new Windows installation the aliases are in the ON position as in image below. When turned on, Windows puts an empty or fake file named python.exe and python3.exe in the directory named %USERPROFILE%AppDataLocalMicrosoftWindowsApps. This is the alias.
Then Microsoft put that directory at the top of the list in the "Path" environment variables.
When you enter "python" in cmd, it searches the directories listed in your "Path" environment variables page from top to bottom. So if you installed Python after a new Windows 10 install then get redirected to the Windows Store, it’s because there are two python.exe’s: The alias in the App Execution Alias page, and the real one wherever you installed Python. But cmd finds the App execution, alias python.exe, first because that directory is at the top of the Path.
I think the easiest solution is to just check the python.exe and python3.exe to OFF as I suggested before, which deletes the fake EXE file files. Based on this Microsoft Devblog, they stated they created this system partially for new Python users, specifically kids learning Python in school that had trouble installing it.
Creating this alias was to help kids just starting Python to install it and focus on learning to code. I think Windows probably deletes those aliases if you install Python from the Windows App Store. We are noticing that they do not get deleted if you manually install from another source.
(Also, the empty/fake python.exe is not really empty. It says 0 KB in the screenshot, but entering "start ms-windows-store:" in cmd opens the Windows App Store, so it probably just has a line with that and a way to direct it to the Python page.)
Finally, as Chipjust suggested, you can create a new alias for Python using something like DOSKEY as explained in this article for example:
How to set aliases for the command prompt in Windows
The main problem here is that the order in the path calls the windows from top to bottom, and that there is python.exe
in %USERPROFILE%AppDataLocalMicrosoftWindowsApps
which is called first if there are no other python.exe
s in the PATH
above that line.
To ensure that the correct python.exe
is called, add the Python interpreter installation folder (containing python.exe
) to the PATH, above %USERPROFILE%AppDataLocalMicrosoftWindowsApps
Here is an example:
- To get to this location, click "Start" → start typing "Env" → Select "Edit the system environment variables" → "Environment variables" button → Select the entry for "Path" in the upper list → Click "Edit".
- Python components should be at the top, as in step 5. If not, move them up by pressing the button in step 6.
I had problems with this as well, where Windows didn’t recognize Python or Anaconda in a double click or cmd (command) prompt.
- Problem: unable to import libraries in "python" cmd in Windows. Instead the Windows "python" cmd took users somewhere they don’t want to go.
- Problem Cause: In Windows "Environmental Variables", Windows adds a python.exe and python3.exe (I don’t know where these link to) in the "%USERPROFILE%AppDataLocalMicrosoftWindowsApps" directory.
Solution: I tried deleting the python*.exe files in the WindowsApp directory, but Windows wouldn’t allow it, so I opened a command prompt in the "%USERPROFILE%AppDataLocalMicrosoftWindowsApps" directory and typed:
del python.exe
del python3.exe
Then I created an environment variable linking to the installed Python interpreter link. In my case, it was C:Anaconda3; C:Anaconda3Scripts, and some others for good measure.
If the Python interpreter is already installed, then go to Apps & features from settings, select Python, and then select modify.
Again select modify and select Next:
Then this window will appear:
Select "add Python to environment variable" and click on the install button. Then again go to apps & features, click modify and click Repair.
Now go to CMD and type Python.
Problem solved.
Adding a bit to the question. Even when I typed pip freeze
, it wasn’t showing anything.
Here’s what I did:
There were multiple instances for the Python application in /AppData/Local/Microsoft/WindowApps
.
I deleted those and then it worked.
You can manually add Python to the Windows path by doing this:
-
Start the Run box and enter sysdm.cpl
-
Go to the Advanced tab and click the Environment Variables button
-
Now you’ll need to locate the relevant Python paths
Here is how a Python application path looks like:
And this is how a Python Scripts path looks like:
-
Select the Path variable, press edit and add both paths (Python application and Python Scripts)
-
If it doesn’t show, press new instead of edit and fill the New User Variable box
This is how my Variable value looks like:
C:UsersRonAppDataLocalProgramsPythonPython37-32;C:UsersRonAppDataLocalProgramsPythonPython37-32Scripts
That’s it! You just added Python to the Windows Path.
Source: Data To Fish
This is a PowerShell script that does the magic.
Remove-Item $env:USERPROFILEAppDataLocalMicrosoftWindowsAppspython*.exe
This is an additional note for anyone using pyenv-win: after turning off the application execution aliases, run pyenv rehash
. You may also need to close/reopen your CMD or PowerShell window.
So, I had the same problem.
My answer was to add python to PATH not only for User variables, it was there, but also for System variables. And now everything works.
So, I’ve got the same problem in VENV.
I solved it by typing >> python**.exe**
But to add every time .exe a little bit nervous.
Also try to type python.exe in cmd.
Because this is a common issue and this appears to be the canonical question, I want to try to give a complete overview of The Python 3.7 Windows Store Fiasco (TM).
Why is it possible for this to happen?
A convergence of two things: the previous introduction of the Python Launcher for Windows in 2011 (hereafter py
), and a Windows 10 update in May 2019 that was apparently intended to make installing Python easier for Windows users.
Oops. Turns out that installation path isn’t great; it bypasses the "lengthy" setup wizard… which contains some options that some users find very useful. It caused other issues, too. Not to mention that it just works in slightly non-standard ways, has limitations on file system access because it’s a Store app, initially couldn’t itself be launched by py
….
Okay, but why do those factors result in the problem?
Since the introduction of py
, by default, Windows Python installers do not add the new Python install to the PATH. Why? Because the entire point of py
is that it uses its own logic to find a Python installation, based on some combination of command-line switches and possibly the source file’s own shebang line. Now your source files can be associated with py
instead of any particular python.exe
, and you can get Linux-like behaviour when double-clicking a file. Meanwhile, by running py
at the command line, you have easy access to whatever you need, and you don’t have to think about which version of Python was installed most recently. So there’s seemingly no good reason to put any of those Python installations on the PATH. It only risks confusing you when, for example, the most recently installed version isn’t the most up-to-date one. Right?
In the update, Windows 10 put a "python.exe" into a Windows Apps-related folder, which is a wrapper app to open a Microsoft Store link. The idea is that it’s on the PATH, but way near the end; so if you have an installed Python, it gets used, and otherwise the wrapper is invoked and helpfully prompts you to install Python – so that you can actually run that random, totally trusted .py
file your friend sent you on Discord.
And it would work perfectly, if your installed Python were on the PATH.
Oops.
(But, you know, py
had been introduced around 8 years prior. You’d think someone at Microsoft would have been aware of the potential issue. Maybe instead of a special shortcut link, they could have made an actual script that checks for the presence of C:Windowspy.exe
or something.)
So what are my options?
-
You can check the option to add new Python versions to the PATH when you install them, and deal with the fact that python
at the command line means a specific one of them. If you need to change that, you can manually tweak your PATH variable.
-
You can just manually tweak the PATH variable after the fact. (or "Modify" a Python installation to fix it.) This is covered in several other answers.
-
Independently of that, you can disable the wrappers, as shown in the top answer. You should probably do this anyway; seeing python
fail at the command line is less aggravating than dealing with a random GUI window popping up and offering to install something for you, especially when you know you have it already.
-
If you want to keep the PATH empty, consider using virtual environments for your projects. Whenever a virtual environment is active, the PATH is temporarily modified such that python
means the Python installation of that environment. It’s quite convenient, really.
-
You might be able to tell your IDEs to use py
instead of a specific Python installation, and it might even be helpful to do so. I don’t know. I don’t use one.
I have put together a powershell snippet, which reorders WindowsApps and Python folder so that Python is first. Run this as Admin:
$appsFld="$env:USERPROFILEAppDataLocalMicrosoftWindowsApps";
$pyPath=(Resolve-Path "$env:USERPROFILEAppDataLocalProgramsPythonPython*")
$Env:Path = (($Env:Path.Split(';') | Where-Object { $_ -ne "$appsFld" }) -join ';');
$Env:Path = (($Env:Path.Split(';') | Where-Object { $_ -ne "$pyPath" }) -join ';');
$Env:Path += ";$pyPath";
$Env:Path +=";$appsFld";
[Environment]::SetEnvironmentVariable("PATH", "$Env:Path", "Machine")
Then I can run python just fine:
> python
Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
Today when I tried to run simple code on Sublime Text 3, the following message appeared:
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
And when I type Python in CMD, it opens the Windows Store for me to download Python 3.7. This problem started today for no good reason. I didn’t change or download anything about Python and already tried reinstalling Python, and the Path environment variable is correct.
Use the Windows search bar to find "Manage app execution aliases". There should be two aliases for Python. Unselect them, and this will allow the usual Python aliases "python" and "python3". See the image below.
I think we have this problem when installing Python because in a new Windows installation the aliases are in the ON position as in image below. When turned on, Windows puts an empty or fake file named python.exe and python3.exe in the directory named %USERPROFILE%AppDataLocalMicrosoftWindowsApps. This is the alias.
Then Microsoft put that directory at the top of the list in the "Path" environment variables.
When you enter "python" in cmd, it searches the directories listed in your "Path" environment variables page from top to bottom. So if you installed Python after a new Windows 10 install then get redirected to the Windows Store, it’s because there are two python.exe’s: The alias in the App Execution Alias page, and the real one wherever you installed Python. But cmd finds the App execution, alias python.exe, first because that directory is at the top of the Path.
I think the easiest solution is to just check the python.exe and python3.exe to OFF as I suggested before, which deletes the fake EXE file files. Based on this Microsoft Devblog, they stated they created this system partially for new Python users, specifically kids learning Python in school that had trouble installing it.
Creating this alias was to help kids just starting Python to install it and focus on learning to code. I think Windows probably deletes those aliases if you install Python from the Windows App Store. We are noticing that they do not get deleted if you manually install from another source.
(Also, the empty/fake python.exe is not really empty. It says 0 KB in the screenshot, but entering "start ms-windows-store:" in cmd opens the Windows App Store, so it probably just has a line with that and a way to direct it to the Python page.)
Finally, as Chipjust suggested, you can create a new alias for Python using something like DOSKEY as explained in this article for example:
How to set aliases for the command prompt in Windows
The main problem here is that the order in the path calls the windows from top to bottom, and that there is python.exe
in %USERPROFILE%AppDataLocalMicrosoftWindowsApps
which is called first if there are no other python.exe
s in the PATH
above that line.
To ensure that the correct python.exe
is called, add the Python interpreter installation folder (containing python.exe
) to the PATH, above %USERPROFILE%AppDataLocalMicrosoftWindowsApps
Here is an example:
- To get to this location, click "Start" → start typing "Env" → Select "Edit the system environment variables" → "Environment variables" button → Select the entry for "Path" in the upper list → Click "Edit".
- Python components should be at the top, as in step 5. If not, move them up by pressing the button in step 6.
I had problems with this as well, where Windows didn’t recognize Python or Anaconda in a double click or cmd (command) prompt.
- Problem: unable to import libraries in "python" cmd in Windows. Instead the Windows "python" cmd took users somewhere they don’t want to go.
- Problem Cause: In Windows "Environmental Variables", Windows adds a python.exe and python3.exe (I don’t know where these link to) in the "%USERPROFILE%AppDataLocalMicrosoftWindowsApps" directory.
Solution: I tried deleting the python*.exe files in the WindowsApp directory, but Windows wouldn’t allow it, so I opened a command prompt in the "%USERPROFILE%AppDataLocalMicrosoftWindowsApps" directory and typed:
del python.exe
del python3.exe
Then I created an environment variable linking to the installed Python interpreter link. In my case, it was C:Anaconda3; C:Anaconda3Scripts, and some others for good measure.
If the Python interpreter is already installed, then go to Apps & features from settings, select Python, and then select modify.
Again select modify and select Next:
Then this window will appear:
Select "add Python to environment variable" and click on the install button. Then again go to apps & features, click modify and click Repair.
Now go to CMD and type Python.
Problem solved.
Adding a bit to the question. Even when I typed pip freeze
, it wasn’t showing anything.
Here’s what I did:
There were multiple instances for the Python application in /AppData/Local/Microsoft/WindowApps
.
I deleted those and then it worked.
You can manually add Python to the Windows path by doing this:
-
Start the Run box and enter sysdm.cpl
-
Go to the Advanced tab and click the Environment Variables button
-
Now you’ll need to locate the relevant Python paths
Here is how a Python application path looks like:
And this is how a Python Scripts path looks like:
-
Select the Path variable, press edit and add both paths (Python application and Python Scripts)
-
If it doesn’t show, press new instead of edit and fill the New User Variable box
This is how my Variable value looks like:
C:UsersRonAppDataLocalProgramsPythonPython37-32;C:UsersRonAppDataLocalProgramsPythonPython37-32Scripts
That’s it! You just added Python to the Windows Path.
Source: Data To Fish
This is a PowerShell script that does the magic.
Remove-Item $env:USERPROFILEAppDataLocalMicrosoftWindowsAppspython*.exe
This is an additional note for anyone using pyenv-win: after turning off the application execution aliases, run pyenv rehash
. You may also need to close/reopen your CMD or PowerShell window.
So, I had the same problem.
My answer was to add python to PATH not only for User variables, it was there, but also for System variables. And now everything works.
So, I’ve got the same problem in VENV.
I solved it by typing >> python**.exe**
But to add every time .exe a little bit nervous.
Also try to type python.exe in cmd.
Because this is a common issue and this appears to be the canonical question, I want to try to give a complete overview of The Python 3.7 Windows Store Fiasco (TM).
Why is it possible for this to happen?
A convergence of two things: the previous introduction of the Python Launcher for Windows in 2011 (hereafter py
), and a Windows 10 update in May 2019 that was apparently intended to make installing Python easier for Windows users.
Oops. Turns out that installation path isn’t great; it bypasses the "lengthy" setup wizard… which contains some options that some users find very useful. It caused other issues, too. Not to mention that it just works in slightly non-standard ways, has limitations on file system access because it’s a Store app, initially couldn’t itself be launched by py
….
Okay, but why do those factors result in the problem?
Since the introduction of py
, by default, Windows Python installers do not add the new Python install to the PATH. Why? Because the entire point of py
is that it uses its own logic to find a Python installation, based on some combination of command-line switches and possibly the source file’s own shebang line. Now your source files can be associated with py
instead of any particular python.exe
, and you can get Linux-like behaviour when double-clicking a file. Meanwhile, by running py
at the command line, you have easy access to whatever you need, and you don’t have to think about which version of Python was installed most recently. So there’s seemingly no good reason to put any of those Python installations on the PATH. It only risks confusing you when, for example, the most recently installed version isn’t the most up-to-date one. Right?
In the update, Windows 10 put a "python.exe" into a Windows Apps-related folder, which is a wrapper app to open a Microsoft Store link. The idea is that it’s on the PATH, but way near the end; so if you have an installed Python, it gets used, and otherwise the wrapper is invoked and helpfully prompts you to install Python – so that you can actually run that random, totally trusted .py
file your friend sent you on Discord.
And it would work perfectly, if your installed Python were on the PATH.
Oops.
(But, you know, py
had been introduced around 8 years prior. You’d think someone at Microsoft would have been aware of the potential issue. Maybe instead of a special shortcut link, they could have made an actual script that checks for the presence of C:Windowspy.exe
or something.)
So what are my options?
-
You can check the option to add new Python versions to the PATH when you install them, and deal with the fact that
python
at the command line means a specific one of them. If you need to change that, you can manually tweak your PATH variable. -
You can just manually tweak the PATH variable after the fact. (or "Modify" a Python installation to fix it.) This is covered in several other answers.
-
Independently of that, you can disable the wrappers, as shown in the top answer. You should probably do this anyway; seeing
python
fail at the command line is less aggravating than dealing with a random GUI window popping up and offering to install something for you, especially when you know you have it already. -
If you want to keep the PATH empty, consider using virtual environments for your projects. Whenever a virtual environment is active, the PATH is temporarily modified such that
python
means the Python installation of that environment. It’s quite convenient, really. -
You might be able to tell your IDEs to use
py
instead of a specific Python installation, and it might even be helpful to do so. I don’t know. I don’t use one.
I have put together a powershell snippet, which reorders WindowsApps and Python folder so that Python is first. Run this as Admin:
$appsFld="$env:USERPROFILEAppDataLocalMicrosoftWindowsApps";
$pyPath=(Resolve-Path "$env:USERPROFILEAppDataLocalProgramsPythonPython*")
$Env:Path = (($Env:Path.Split(';') | Where-Object { $_ -ne "$appsFld" }) -join ';');
$Env:Path = (($Env:Path.Split(';') | Where-Object { $_ -ne "$pyPath" }) -join ';');
$Env:Path += ";$pyPath";
$Env:Path +=";$appsFld";
[Environment]::SetEnvironmentVariable("PATH", "$Env:Path", "Machine")
Then I can run python just fine:
> python
Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> quit