[英]Running a python script in Windows gives "Unable to Create Process Using ..." when python.exe set to 'run as administrator'
I used to be able to call python scripts directly from the command line in Windows.我曾经能够直接从 Windows 的命令行调用 python 脚本。 eg:例如:
C:\\SomeScript.py C:\\SomeScript.py
But after setting the python executable to 'Run as Administrator' in the compatibility settings, I always get the cryptic error "Unable to Create Process using' ... followed by path of the python file I'm trying to run:但是在兼容性设置中将 python 可执行文件设置为“以管理员身份运行”后,我总是收到神秘错误“无法使用创建进程”......后跟我试图运行的 python 文件的路径:
Unable to create process using 'C:\\python\\python.exe "C:\\SomeScript.py" '无法使用 'C:\\python\\python.exe "C:\\SomeScript.py" ' 创建进程
I get the same error if I try and run the file from Explorer (albeit flashing on my screen briefly, or if I run the script from the 'Send To' popup.如果我尝试从资源管理器运行该文件(尽管在我的屏幕上短暂闪烁,或者如果我从“发送到”弹出窗口运行脚本),我会遇到同样的错误。
This was caused by the Python executable being set to 'Run As Administrator.'这是由于 Python 可执行文件被设置为“以管理员身份运行”所致。 in the compatibility settings;在兼容性设置中; presumably because windows could not load the UAC form to escalate privileges.大概是因为 Windows 无法加载 UAC 表单来提升权限。
There are two possible solutions.有两种可能的解决方案。
Remove the 'Run as Administrator' setting删除“以管理员身份运行”设置
Pass the script's path as an argument to Python.exe rather than calling it directly, which allows windows to prompt for escalation correctly.将脚本的路径作为参数传递给 Python.exe 而不是直接调用它,这允许 Windows 正确提示升级。
Ie Instead of即代替
c:\\SomeScript.py c:\\SomeScript.py
run跑
c:\\python\\python.exe c:\\SomeScript.py c:\\python\\python.exe c:\\SomeScript.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.