Python2.7Windows静默安装程序(.msi)-设置路径的命令行选项?

2024-06-28 20:29:19 发布

您现在位置:Python中文网/ 问答频道 /正文

使用静默安装程序(.msi)在Windows上安装python 2.7时,是否有命令行选项将python添加到path环境变量中,如GUI选项?

Python 3.5安装程序默认包含一个PrependPath=0选项,但是Python 2.7可以使用它吗?

https://docs.python.org/3/using/windows.html

看起来这个问题已经在这里讨论过了,但是Python2.7没有解决方案?

https://bugs.python.org/issue3561

编辑


这批命令太棒了!!!

setx\M PATH%PATH%;C:\ Python\Python27;C:\ Python\Python27\Scripts

但setx会将存储的%PATH%字符串截断为1024字节。


Tags: path命令行httpsorgdocswindows选项环境变量
2条回答

Python MSI安装程序可以从2.4开始更新系统路径。只需将ADDLOCAL=ALL添加到命令行。在系统传播之前,您必须重新启动它。

msiexec /i "python-2.7.11.amd64.msi" /passive /norestart ADDLOCAL=ALL

https://www.python.org/download/releases/2.4/msi/

我观察到,在Windows 7(Professional)上,使用python 2.7.14x64,不需要重新启动python就可以添加到PATH。只要在安装之后启动一个新的命令窗口,python就会在路径中。

您可以通过运行msi来确定安装是否需要重新启动,如下所示:

start/wait "" msiexec /i "python-2.7.11.amd64.msi" /passive /norestart ADDLOCAL=ALL
if %errorlevel% == 3010 ( echo Success: reboot required ) else (if %errorlevel% == 0 ( echo Success ) else ( echo Installation failed with error code %errorlevel% ) )

也就是说,如果%errorlevel%是3010(需要ERROR_SUCCESS_REBOOT),则需要重新启动。使用start/wait会导致cmd.exe等待msiexec进程完成。这允许msiexec返回状态对cmd.exe可用。

顺便说一下,如果您希望Python的安装对系统上的所有用户都可用,那么您可能希望在命令行中包含选项ALLUSERS=1

相关问题 更多 >