简体   繁体   English

在Windows上安装Python x64之后,无法从资源管理器启动脚本

[英]After Python x64 install on windows can't launch script from explorer

I needed to install Python 3.6.1 x64 for a project on windows. 我需要在Windows上为项目安装Python 3.6.1 x64。 I uninstalled 3.6.1 x86 and installed 3.6.1 x64. 我卸载了3.6.1 x86,然后安装了3.6.1 x64。 I made sure that my PATH env var is pointing to the new install. 我确保PATH env var指向新安装。 I then associated py files with the correct python.exe: C:\\Program Files\\Python36\\python.exe instead of: C:\\Program Files (x86)\\Python36-32\\python.exe 然后,我将py文件与正确的python.exe关联:C:\\ Program Files \\ Python36 \\ python.exe而不是:C:\\ Program Files(x86)\\ Python36-32 \\ python.exe

I can run a script directly from a cmd window by calling python no problem: python myscript.py 我可以通过调用python没问题直接从cmd窗口运行脚本:python myscript.py

but if I double click it displays a cmd windows bot nothing in it. 但是,如果我双击它,将不显示任何cmd Windows Bot。

If I "Open with" it won't load, just giving me the waiting cursor for a couple of seconds. 如果我“打开方式”将不会加载,只需给我几秒钟的等待光标。 Even after I browsed for the new python.exe 即使我浏览了新的python.exe之后

What am I missing here? 我在这里想念什么?

Everything was working fine for Python x86 Python x86一切正常

Thanks! 谢谢!

Le sigh, two issues happening. 遗憾的是,发生了两个问题。 Something was borked with the Python install somewhere, a complete uninstall and reinstall of 3.6.1 x64 fixed that for general python execution. 某处的Python安装有些令人讨厌,完全卸载并重新安装3.6.1 x64可以解决一般python执行问题。

Secondly, I'm using Pywinauto which is why I need x64 to access x64 app's UI. 其次,我正在使用Pywinauto,这就是为什么我需要x64来访问x64应用程序的UI的原因。 Apparently it also needs elevated user rights ie admin. 显然,它还需要提升的用户权限,即admin。 So if I double click a script it just hangs with no feedback, errors etc because the launcher isn't run with admin rights. 因此,如果我双击一个脚本,它会挂起而没有任何反馈,错误等,因为启动器未以管理员权限运行。

I didn't catch this because I was always executing python manually from an elevated cmd window. 我没有意识到这一点,因为我总是从提升的cmd窗口手动执行python。 If I find a way to always execute the launcher as admin I'll update here. 如果我找到始终以管理员身份执行启动器的方法,请在此处进行更新。

UPDATE: Here's an in depth thread on getting Python to elevate execution privileges on Windows: How to run python script with elevated privilege on windows 更新:这是深入了解如何在Windows上提升Python执行特权的线程: 如何在Windows上以提升的特权运行python脚本

It was far easier for me to write a Powershell script to do this job: 对我来说,编写Powershell脚本来完成这项工作要容易得多:

# ========================================= Admin Rights =======================================================
function asAdmin
{
    [string]$cmdPath = $args[0]
    if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$cmdPath`"" -Verb RunAs; exit }
}

asAdmin $PSCommandPath

Start-Process "pythonw" "$PSScriptRoot\myPythonScriptWithUI.pyw"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM