CMD opens window store when I type python

174,504

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

This is a PowerShell script that does the magic.

Remove-Item $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\python*.exe

Solution 5

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.

Share:
174,504

Related videos on Youtube

João Vitor Degrandi
Author by

João Vitor Degrandi

Updated on August 02, 2022

Comments

  • João Vitor Degrandi
    João Vitor Degrandi almost 2 years

    Today when I tried to run a 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 downloaded anything about Python and already tried reinstalling Python, and the Path is correct.

    • ChipJust
      ChipJust over 4 years
      What if you type py from the command line instead of python?
    • fabda01
      fabda01 over 4 years
      How about this solution?
    • Cadoiz
      Cadoiz almost 4 years
      I also think, it could be a duplicate to the question referenced by @yellow (it is linked to a specific answer)
    • Cagri
      Cagri about 3 years
      @ChipJust why do I have to type py instead of python all of a sudden?
    • ChipJust
      ChipJust about 3 years
      @Cagri 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.
    • nmz787
      nmz787 about 2 years
      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.
  • João Vitor Degrandi
    João Vitor Degrandi over 4 years
    I checked the box
  • Ben Rauzi
    Ben Rauzi over 4 years
    Okay, then go to 'Tools' in Sublime Text, 'Build System', then make a new build system and point it to your Python Directory
  • Martijn Pieters
    Martijn Pieters about 4 years
    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.
  • W. Elbashier
    W. Elbashier almost 4 years
    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\WindowsApps
  • imix
    imix almost 4 years
    I had the same problem. "App Installer" were both off. I had to switch them on and off again to stop the problem.
  • np8
    np8 over 3 years
    This is actually the correct answer but the negative votes might be from the (previous) animated GIF + language of the printscreen + lack of explanation.
  • np8
    np8 over 3 years
    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.
  • james-see
    james-see over 3 years
    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!
  • carlo
    carlo over 3 years
    I don't get why is this beneficial, could you elaborate on than?
  • Dmitri DB
    Dmitri DB over 3 years
    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 way
  • betafractal
    betafractal over 3 years
    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.
  • betafractal
    betafractal over 3 years
    @carlo 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.
  • imnhasan
    imnhasan about 3 years
    thanks brother it helps me & save my time :)
  • andrew k
    andrew k almost 3 years
    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.
  • CodingMatters
    CodingMatters almost 3 years
    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)
  • Jordy
    Jordy almost 3 years
    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.
  • Haya SVU
    Haya SVU over 2 years
    Thanks it helps
  • Sindre Bakke Øyen
    Sindre Bakke Øyen over 2 years
    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.
  • Leon
    Leon over 2 years
    Why? Could you provide more information about this step?
  • Karl Knechtel
    Karl Knechtel over 2 years
    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.
  • Krypt
    Krypt about 2 years
    I would really appreciate if someone will put actual menu location instead of what "search for". My windows is localized :(
  • betafractal
    betafractal about 2 years
    @Krypt 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 aliases