使用 Python 下载并安装 .exe 文件

Download and Install a .exe File using Python

我想为我的项目创建一个自动更新程序,它可以从 Internet 下载并安装文件。我已经完成了如何使用所需的名称将文件下载到所需的位置。我卡住的地方是如何安装文件。

到目前为止我写的代码:

from urllib.request import urlretrieve
import getpass

url = 'https://sourceforge.net/projects/artigence/files/latest/download'

print('File Downloading')

usrname = getpass.getuser()
destination = f'C:\Users\{usrname}\Downloads\download.exe'

download = urlretrieve(url, destination)

print('File downloaded')

并且文件已下载到我的下载文件夹中。现在,如何使用 python 安装 .exe 文件?

您将需要使用 subprocess 模块来执行 .exe 个文件。

import subprocess

cmd = "{download location} batch.exe"

returned_value = subprocess.call(cmd, shell=True)  # returns the exit code in unix
print('returned value:', returned_value)

refer

我强烈建议不要为此使用 pyautogui