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

使用Python下载并安装.exe文件,python,python-3.x,urllib,Python,Python 3.x,Urllib,我想为我的项目创建一个自动更新程序,从internet下载并安装一个文件。我已经完成了如何用所需的名称将文件下载到所需的位置。我遇到的问题是如何安装该文件 到目前为止,我已经编写了以下代码: from urllib.request import urlretrieve import getpass url = 'https://sourceforge.net/projects/artigence/files/latest/download' print('File Downloading')

我想为我的项目创建一个自动更新程序,从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文件?

您将需要使用
子流程
模块来执行
.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)


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

您可以使用它来控制应用程序。看看“安装.exe”。。。如何使用
os
.exe
安装应用程序本质上是它自己的一个命令,因此通过shell脚本或bat文件调用它就足够了,或者在这种情况下,如果文件是
installer.exe
,那么我们在安装时是否需要选择选项,例如
install location
和众多的
next
按钮?如何使用
os
?您可以在线检查安装程序,并希望找到一些参数,允许您跳过它,但如果是安装向导,您将别无选择,只能使用
pyautogui
。这可能会让
pyautogui
变得混乱,因为它依赖于屏幕的(x,y)坐标,因此您可能会面临许多不需要的兼容性问题。是的,这就是我建议
pyautogui
在所有情况下都能工作的原因:-)。凌乱是的,但仍然可靠:)