命令提示符运行python出现拒绝访问_Python / python3在命令提示符下执行,但无法正常运行...

I've solved the issue and am posting to save others from my hours of pain.

Problem

On Windows 10,

Python is installed in C:\Python and added to Environment Variables, but will not properly run programs.

Typing python myscript.py in CMD does not run the program but does not produce any errors.

Typing C:\Python\python.exe myscript.py correctly runs the code.

Solution

Navigate to C:\Users\Username\AppData\Local\Microsoft\WindowsApps\python.exe in CMD and type del /f python.exe.

What was wrong

The file located at C:\Users\MyUsername\AppData\Local\Microsoft\WindowsApps\python.exe is viewed before the Environment Variables in PATH. This file just opens the download page for Python in Edge.

You need to delete this file or rename it, but the items in this folder are protected by Microsoft. You get Error 0x80070780 if you try to delete this file with file explorer. In order to delete it you need to navigate to the folder in CMD with administrator privileges and type the above to remove this file.

I hope this helps someone.

解决方案

Putting this Q/A into the right format so the question does not look open/unanswered

Solution from original poster; tested and worked on my system

Solution

In C:\Users\*Username*\AppData\Local\Microsoft\WindowsApps delete python.exe. However, because these files are protected, chances are you will get an error message when trying to delete the file. In that case, you either have to use your administrator account to delete python.exe, or you call a cmd-window with administrator privileges and force delete ''''rm -f C:\Users*Username*\AppData\Local\Microsoft\WindowsApps\python.exe''''

About the solution

python.exe is not the python - executable one would believe it to be, but invokes the download page for python to be opened in the Edge browser or the Microsoft App Store. The question of "who would come up with such a sadistic thing" and "why?." shall remain unanswered at this point. Fact is that calling python executes this faux- python.exe before the PATH Environment Variables are invoked.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值