似乎一夜之间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,但也没有帮助。还有什么我该看的吗?
这不是PowerShell的解决方案,但除了MINGW64之外,我也遇到了同样的问题。我绕过它切换到Windows子系统Linux(我想做的无论如何)作为我的终端,只是一般和在VSCode。这篇文章描述得很好:
如何配置VS Code (windows)使用Ubuntu应用程序作为终端
总而言之:
1)从Windows应用商店安装Ubuntu
2)修改默认bash CMD -> wslconfig /setdefault Ubuntu
--- 对于VSCode
3) 重新启动 VSCode
4)在VSCode中将“terminal.integrated.shell.windows”更改为“C:\WINDOWS\System32\bash.exe”(更多详细信息见上面的帖子)
现在在VSCode和WSL (Bash on Ubuntu on Windows)中运行顺畅。对你来说至少是个暂时的解决办法。
研究
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps中的所有文件都是占位符,它们指向的文件实际上位于C:\Program Files\ WindowsApps中的某个位置,而该位置的权限恰好完全被拒绝。
看来我在这个问题的副本中所做的陈述是正确的:
“似乎他们并没有真正考虑到分发方法会影响权限!”
无法在Windows上的Git Bash中安装pylint (Windows Store)
由于WindowsApps的分发方法,权限被搞砸了:
有趣的是,它说“用户”组可以读取和执行文件,以及我的特定用户,但管理员组只能列出文件夹内容,这是出于一些可笑的无法理解的原因。当尝试在文件资源管理器中访问文件夹时,它甚至拒绝显示文件夹内容,所以这也有一些可疑的地方。
有趣的是,尽管在CMD中执行python工作正常,但“WindowsApps”文件夹在列出其所在目录中的文件时不会显示,并且试图导航到该文件夹会生成“权限被拒绝”错误:
尝试更改权限需要首先更改所有者,因此我将所有者更改为Administrators组。在那之后,我试图改变管理员组的权限,以包括完全控制,但它无法改变这一点,因为“访问被拒绝”(duh, Micro$ucks,这就是我们试图改变的!)
这个权限错误发生在很多文件上,我用Alt+C在重复消息上快速点击“继续”,但这仍然花费了太长时间,所以我取消了这个过程,导致弹出以下警告消息:
现在我无法将TrustedInstaller用户设置为WindowsApps文件夹的所有者,因为它没有显示在用户/组/内置安全原则/其他对象的列表中。*
*实际上,根据本教程,您可以通过在对象名称文本框中输入NT Service\TrustedInstaller将所有者切换回TrustedInstaller。
解决方案
没有解决办法。基本上,我们完全完蛋了。漂亮的举动,微软。
这个问题太常见了,不可能一直存在。大多数答案和说明都未能解决这个问题。下面是在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.
这是由于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中运行
对于那些想要使用微软商店版本的Python的人来说,在@Zooba修复了相关的“管理应用程序执行别名”之后,并且正在使用Git For Windows Git - BASH(也称为BASH through msys2 mintty),解决方案可能只是记住使用winpty进行调用。
winpty python3
但是,如果系统有其他版本的Python,请确保这些副本已被删除(例如从python.org安装的那些)或包含在其特定的捆绑应用程序中(例如OSGeo4W)(可能需要重新排序环境变量)。
Why, if winpty is forgotten, is it a permission error? For the first time it runs, the Microsoft Store stubs are conflicting with the permissions available to msys. A lot of the other answers go into the details of what is going on and why it feels weird. The short answer, is that the stub is trying to be a convenience short-cut to the Microsoft Store. If you launch it with winpty, it can do that. After that first time, it continues to need winpty for both related and unrelated reasons to the Microsoft Store.