似乎一夜之间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,但也没有帮助。还有什么我该看的吗?


当前回答

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

其他回答

最简单的方法是修改PATH和PYTHONPATH环境变量,以确保在搜索本地WindowsApp文件夹之前搜索包含适当python二进制文件的文件夹。您可以通过打开控制面板并搜索“env”来访问环境变量。

我也遇到了同样的问题,但除了Python被阻止之外,Scripts文件夹中的所有程序也被阻止了。其他关于别名、path和winpty的答案没有帮助。

我终于发现这是我的反病毒(Avast),因为某些原因,它在一夜之间决定阻止所有编译的python脚本。

幸运的是,修复方法很简单:只需将整个Python目录列入白名单。这里有完整的解释。

对于那些想要使用微软商店版本的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.

这个问题太常见了,不可能一直存在。大多数答案和说明都未能解决这个问题。下面是在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.

在环境变量中添加python文件夹的路径,就可以工作了

1.搜索环境变量

2.寻找系统变量section,并在其中找到名为path的变量

3.双击path并添加指向python文件夹的新路径,就是这样。

python文件夹通常在 C: \用户(“用户名”)\ AppData \本地Python \程序\ \ Python39