CMD opens Windows Store when I type 'python'

CMD открывает Windows Store, когда я набираю "python"

Сегодня, когда я попытался запустить простой код в Sublime Text 3, появилось следующее сообщение:

Python не найден, но может быть установлен из Microsoft Store: https://go.microsoft.com/fwlink ?LinkId = 2082640

И когда я набираю Python в CMD, он открывает Windows Store для загрузки Python 3.7. Эта проблема началась сегодня без уважительной причины. Я ничего не менял и не загружал о Python и уже пробовал переустановить Python, и переменная окружения Path указана правильно.

Переведено автоматически
Ответ 1

Используйте панель поиска Windows, чтобы найти "Управление псевдонимами выполнения приложений". Для Python должно быть два псевдонима. Отмените их выбор, и это позволит использовать обычные псевдонимы Python "python" и "python3". Смотрите изображение ниже.

Введите описание изображения здесь

Я думаю, что у нас возникла эта проблема при установке Python, потому что в новой установке Windows псевдонимы находятся в положении ON, как на изображении ниже. При включении Windows помещает пустой или поддельный файл с именем python.exe и python3.exe в каталог с именем %USERPROFILE%\AppData\Local\Microsoft\ WindowsApps. Это псевдоним.

Введите описание изображения здесь

Затем Microsoft поместила этот каталог в начало списка в переменных окружения "Path".

Введите описание изображения здесь

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.

Ответ 2

This is a PowerShell script that does the magic.

Remove-Item $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\python*.exe
Ответ 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.

Ответ 4

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.