CMD opens Windows Store when I type 'python'
Asked Answered
F

14

358

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.

Fusibility answered 7/11, 2019 at 18:22 Comment(6)
What if you type py from the command line instead of python?Cauca
How about this solution?Spacetime
I also think, it could be a duplicate to the question referenced by @yellow (it is linked to a specific answer)Inquisitive
@Cauca why do I have to type py instead of python all of a sudden?Postcard
@Postcard This question has some good information about it, but the short answer is I don't know exactly. It depends on key bindings in your registry on Windows. The Python installer has been putting the py wrapper there instead of python.exe for a while, which is nice because it honors shebang.Cauca
how do I disable MS Store from opening, and just print the standard 'python' is not recognized as an internal or external command, operable program or batch file.Slippery
R
712

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.

Enter image description here

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%\AppData\Local\Microsoft\WindowsApps. This is the alias.

Enter image description here

Then Microsoft put that directory at the top of the list in the "Path" environment variables.

Enter image description here

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.

The first time I ran into this problem, I manually deleted the python.exe and python3.exe files but when I restarted the files regenerated. That prompted me to search for the App Execution Aliases page and uncheck the box, which solved it for me, by not allowing the files to regenerate.

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, 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.)

One alternative, 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

Another alternative is to delete the user path environment variable that points to the alias files, %USERPROFILE%\AppData\Local\Microsoft\WindowsApps, but the App Execution Aliases handle more apps than just python, and deleting the path from environment variables breaks all the other apps that have execution aliases in that directory; which on my PC includes notepad, xbox game bar, spotify, monitoring software for my motherboard, paint, windows subsystem for android, to name a few. Also if you think about it, the average Windows user is unfamiliar editing environment variables and on school and business owned computers requires administrative access. So deleting the path to ...\WindowsApps, from the path environment variable, is not ideal.

Roebuck answered 8/11, 2019 at 21:26 Comment(16)
I had the same problem. "App Installer" were both off. I had to switch them on and off again to stop the problem.Owl
This answer provides only workarounds. The root cause is that there is "MS made" python.exe in a folder listed in the PATH variable. This folder is %USERPROFILE%\AppData\Local\Microsoft\WindowsApps. Just make sure your python installation path is listed in the PATH above the WindowsApps, that's all. This is covered in the user aattk's answer below.Neilneila
This was ridiculous that I had to go do this. Why can't Microsoft just leave me alone. I installed Python into a local directory by unzipping it and the command should just work. Just stop!Inference
I don't get why is this beneficial, could you elaborate on than?Smail
Yeah I fail to see what's really cool about annoyingly messing with my scripts on various installs of windows too. Consistency goes a long wayAbutment
@Smail I tried to make clear why this is beneficial which is mostly for new users, there is more detail in the link I provided as well. Thank you for the constructive feedback.Roebuck
woke up this morning to find this problem. Suspect windows updated overnight, curr ver 21H1 Build 19043.1165 When I deselected the entries for python and pip, the links in this directory were deleted. (yes I had multiple entries, possibly due to previous installs, uninstalls, upgrades of windows python app) C:\Users\bmt\AppData\Local\Microsoft\WindowsApps then attempting python would return this message. "'python' is not recognized as an internal or external command, operable program or batch file." selecting python again, resulted in cmd > python working again. (similarly for pip)Chic
I tried this and it didn't work immediately. The thing is, I got 2 accounts on my PC. It seems like the aliases from my other account were interfering. I already turned it off on my main account, but the app store was still popping up. When I turned the app aliases off on my other account it worked immediately. Just placing this here if anyone else has the same problem.Pegg
Wtf, why would Windows ever create an alias for python to open windows store???? That shit makes no sense... My PATH variable had the path to python as its first entry, and still windows store opened when I hit python in cmd.Pukka
I would really appreciate if someone will put actual menu location instead of what "search for". My windows is localized :(Mcmath
@Mcmath click the Windows icon bottom left, then click the gear icon to open Settings, then click Apps: Uninstall, defaults, optional features, then there should be some option in blue text the second line for me is "App execution aliases" which is where you can uncheck the python aliasesRoebuck
Thanks, the solution worked for me. 1. I Unticked the app execution aliases that pointed to python.exe 2. Add python to path, on above %USERPROFILE%\AppData\Local\Microsoft\WindowsAppsBasting
Just chipping in to mention that both the Environment Variables and the App Execution fixes were only part of the solution. The only way I could get Python working was to use "py" instead of "python" in CMD. The latter would just error out.Phosphoprotein
@CakePrincess The App Execution switch removes the preinstalled Environment Variables, so it is one solution. You wrote it as if they are different solutions. So I wonder what exactly you did with your user & system path variables, did you try to delete manually and then turned the App Executions off? If yes, you may have accidently deleted the wrong path. Or like me, first time I deleted the preinstalled env variables but they regenerated which made me look for the App Executions. If your python installed correct then shouldn't need it but if nothing else works glad at least the alias works.Roebuck
there's something ironic about Microsoft, who any other time acts like they are married to backward compatibility (ex: ever tried naming a file/folder "con"?), deciding to break EVERYONE's Python scripts by pointing pointing the top PATH to a dummy executable so that even if you already had Python, it doesn't find the real Python. If this is really about making Python easier to install, what does it matter which Python you use?Haya
My god this makes it into this years top ten list of Microsoft MomentsOdine
G
43

This is a PowerShell script that does the magic.

Remove-Item $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\python*.exe
Googly answered 9/11, 2020 at 15:20 Comment(0)
D
31

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:

Select next

Then this window will appear:

Select add Python to environment variable

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.

Davon answered 3/6, 2020 at 7:53 Comment(1)
This is the only correct answer! Do not install python via app store!!! Use the offical installer from python and everything works python.org/downloads/windowsStound
S
29

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%\AppData\Local\Microsoft\WindowsApps which is called first if there are no other python.exes 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%\AppData\Local\Microsoft\WindowsApps

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".

Enter image description here

  • Python components should be at the top, as in step 5. If not, move them up by pressing the button in step 6.
Statvolt answered 3/4, 2020 at 11:3 Comment(4)
Note that your animated GIF is too large to be uploaded to the Stack Overflow imgr account (limited to 2MB, this image is nearly 10MB). The current hosting option on your own site, is not guaranteed to be stable for the lifetime of your answer (which could easily be decades), please find a way to limit its size and then move it to imgr.Calcareous
This is actually the correct answer but the negative votes might be from the (previous) animated GIF + language of the printscreen + lack of explanation.Neilneila
This is okay, but you'll have to redo it if you ever uninstall/reinstall python or install different versions or distributions of python. Not super difficult, but you could solve this once, permanently, by turning off the alias in Manage app execution aliases page.Roebuck
Moving python to the first line in the Path had no effect for me, the Windows Store continued to launch until I followed the execution aliases answer above.Summertime
N
7

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%\AppData\Local\Microsoft\WindowsApps" 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%\AppData\Local\Microsoft\WindowsApps" 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:\Anaconda3\Scripts, and some others for good measure.

Norven answered 9/5, 2020 at 16:6 Comment(1)
I followed the aforementioned steps of the preferred answer and I still got the MS store popping up. Your solution saved my day. Thanks. By the way, you can use this command to get to that directory: cd "%USERPROFILE%\AppData\Local\Microsoft\WindowsAppsSeptima
T
4

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:\Windows\py.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.

Tinea answered 24/1, 2022 at 7:59 Comment(2)
Reading further, it appears that Microsoft and the Python dev team consciously collaborated to get Python into the Store. Which makes it even more mystifying that nobody accounted for this interaction.Tinea
Good to have a summary of events, I was aware of these facts but seeing them gathered will help users who are just starting out with Python on Windows.Forborne
H
3

As a person who does Python development in Sublime Text, I know you said the Python interpreter path was correct, but when you install the Python interpreter make sure to tick the option to add Python to PATH.

I had the same issue back in the day till I did this.

pythoninstaller.png

Hobart answered 8/11, 2019 at 23:24 Comment(2)
I checked the boxXylography
Okay, then go to 'Tools' in Sublime Text, 'Build System', then make a new build system and point it to your Python DirectoryHobart
U
2

You can manually add Python to the Windows path by doing this:

  1. Start the Run box and enter sysdm.cpl

    Enter image description here

  2. Go to the Advanced tab and click the Environment Variables button

    Enter image description here

  3. Now you’ll need to locate the relevant Python paths

    Here is how a Python application path looks like:

    Enter image description here

    And this is how a Python Scripts path looks like:

    Enter image description here

  4. Select the Path variable, press edit and add both paths (Python application and Python Scripts)

    Enter image description here

  5. If it doesn't show, press new instead of edit and fill the New User Variable box

    Enter image description here

    This is how my Variable value looks like:

    C:\Users\Ron\AppData\Local\Programs\Python\Python37-32;C:\Users\Ron\AppData\Local\Programs\Python\Python37-32\Scripts

    Enter image description here

That’s it! You just added Python to the Windows Path.

Source: Data To Fish

Ultimately answered 30/8, 2020 at 2:36 Comment(1)
I have it added but this does not solve the problem.Adhibit
I
2

I have put together a powershell snippet, which reorders WindowsApps and Python folder so that Python is first. Run this as Admin:

$appsFld="$env:USERPROFILE\AppData\Local\Microsoft\WindowsApps"; 
$pyPath=(Resolve-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python*\")
$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

Inbound answered 19/10, 2022 at 15:35 Comment(1)
you can also manually go to System Environment Variables menu and press Move Down for the WindowsApps line hereAntonioantonius
S
1

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.

Squishy answered 9/2, 2021 at 20:15 Comment(1)
Why? Could you provide more information about this step?Alliber
T
1

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.

enter image description here

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.

Tatianna answered 9/11, 2021 at 17:26 Comment(0)
B
0

None of the above methods solved my problem.
Let me share my solution with you.

Key Fix ( Solution )

Start -> Search -> Type:cmd -> Launch

  1. See what Python is leading to
    > where python
  2. You should change the last folder to PythonXXX
    > cd %USERPROFILE%\AppData\Local\Programs\Python\Python312
  3. Add a python3 hard link pointing to the correct python.exe
    > mklink /H python3.exe python.exe

Investigation

Let's see what's inside PATH

C:\Users\user>path
PATH=...omit..
C:\cr5000\Lightning\programs;
C:\Users\user\AppData\Local\Programs\Python\Python312\Scripts\;
C:\Users\user\AppData\Local\Programs\Python\Python312\;
C:\Users\user\AppData\Local\Microsoft\WindowsApps;

You can see above python and script are both before WindowsApps. I keep getting python2 and 'import site' failed when I try to run python with any script.

C:\Users\user>python
'import site' failed; use -v for traceback
Python 2.0 (#0, Oct  9 2020, 12:12:52) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> ^Z^Z

Known facts so far:

  1. Alias has been turned off
  2. PATH has been added and rearranged
C:\Users\user>where python
C:\cr5000\Lightning\programs\python.exe
C:\Users\user\AppData\Local\Programs\Python\Python312\python.exe

Aha, there is a sneaky python.exe deep inside another program's folder, this is my unique software conflations situation, and cr5000 is in system PATH, I can't make the user PATH take precedence over the system, so I have to add an python3 alias with symbolic link.

C:\Users\user>python3
'python3' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\user\AppData\Local\Programs\Python\Python312>mklink /H python3.exe python.exe
Hardlink created for python3.exe <<===>> python.exe

C:\Users\user>python3
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z^Z

So... I finally fixed my problem.

Beaubeauchamp answered 22/12, 2023 at 8:2 Comment(0)
U
0

Py is an alias useful for other tasks if you have seveal versions of python. So the app execution aliases button unchecking is not recommended. The "new" way to find out the python version installed is typing in CMD

py -V
Unstring answered 29/2 at 10:18 Comment(0)
S
-5

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.

Sublimity answered 24/6, 2020 at 17:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.