似乎一夜之间Windows 10的更新破坏了Python。只是试图运行python——version返回一个“Permission Denied”错误。三个更新都没有;KB4507453、KB4506991或KB4509096似乎是罪魁祸首,但出现问题的时间令人怀疑。与其搞砸回滚,我希望有一个我错过的更简单的解决方法。

python的权限是“-rwxr-xr-x”,除了让Windows更新在安装昨晚的补丁后重新启动机器外,我没有改变任何东西。

根据系统信息,我正在运行10.0.18362

还应该注意,无论我(尝试)从git-bash执行Python使用“作为管理员运行”或不,如果我尝试使用PowerShell,它只是打开Windows商店,好像应用程序没有安装,所以我认为它不能看到我的/c/Users/david/AppData/Local/Microsoft/WindowsApps/文件夹的内容。

我还尝试重新安装Python 3.7.4,但也没有帮助。还有什么我该看的吗?


当前回答

Windows 10

开放式控制面板 单击系统 单击高级系统设置链接 单击“环境变量”按钮 在System Variables部分中找到PATH环境变量并选择它 单击编辑(如果PATH环境变量不存在,则单击新建) 在“编辑环境变量”窗口中指定PATH环境变量的值 单击OK 单击OK关闭所有剩余窗口 重新打开命令提示符窗口,执行python——version命令

其他回答

这个问题太常见了,不可能一直存在。大多数答案和说明都未能解决这个问题。下面是在Windows 10上可以做的事情:

Type environment variables in the start search bar, and open Edit the System Environment Variables. Click Environment Variables... In the System Variables section, locate the variable with the key Path and double click it. Look for paths pointing to python files. Likely there are none. If there are, select and delete them. Create a new variable set to the path to your python executable. Normally this is C:\Users\[YOUR USERNAME HERE]\AppData\Local\Programs\Python\Python38. Ensure this by checking via your File Explorer. Note: If you can't see AppData, it's because you've not enabled viewing of hidden items: click the View tab and tick the Hidden Items checkbox. Create another variable pointing to the Scripts directory. Typically it is C:\Users\[YOUR USERNAME HERE]\AppData\Local\Programs\Python\Scripts. Restart your terminal and try typing py, python, python3, or python.exe.

节省时间: 使用WSL和vscode远程扩展来正确地使用python,即使是win10 别忘了virtualenv! 有用的https://linuxize.com/post/how-to-install-visual-studio-code-on-ubuntu-18-04/

这是由于Windows应用程序执行别名在Git-Bash中的工作方式。

这是MSYS2中一个已知的问题,无法通过IO_REPARSE_TAG_APPEXECLINK访问Windows重解析点

作为一种变通方法,您可以为在底层使用cmd.exe的函数调用命名别名。

将以下内容添加到~/。bashrc文件(::

function python { cmd.exe /c "python $1 $2 $3";}

对于python,我建议关闭应用程序执行别名,就像接受的答案一样,但对于像winget这样专门通过windows商店分发的库,这是最好的选择。

进一步的阅读

bash: Local/Microsoft/WindowsApps/python3: Permission denied . sh 从bash运行时拒绝权限 由于exec格式错误#234,winget无法在WSL2中运行

确保C:\Python39\和C:\Python39\Scripts\被添加到系统路径变量和用户路径变量中

据我所知,这是由最近添加到Windows商店的Python 3.7版本冲突引起的。这看起来像是在%USERPROFILE%\AppData\Local\Microsoft\WindowsApps文件夹中添加了两个名为Python .exe和python3.exe的“存根”,在我的例子中,这是插入到PATH中现有的Python可执行文件条目之前的。

将这个条目移到正确的Python文件夹下面(部分地)纠正了这个问题。

纠正它的第二部分是在Windows搜索提示符中输入管理应用程序执行别名,并完全禁用Python的商店版本。

你可能只需要做第二部分,但在我的系统上,我做了这两个更改,现在一切都恢复正常了。