Gauthier Buttez
Gauthier Buttez

Reputation: 1203

How to execute MSI installer from python script?

I need to install node.js from my python script. I tried these solutions:

Is it possible to install an msi using python?

install .rpm or .msi file through python script

I tried with these various code:

os.system('msiexec /i %s /qn' % 'node_install.msi')
subprocess.check_call(["msiexec /i node_install.msi"])
subprocess.Popen('node_install.msi')

But I get the error message:

[WinError 193] %1 is not a valid Win32 application

Here is my script which downloads successfully the MSI file:

if platform.architecture()[0] == "64bit":
    wget.download('https://nodejs.org/dist/v12.15.0/node-v12.15.0-x64.msi','node_install.msi')
    logger.info("We will try now to install NodeJS 64Bits. Please follow the installation process.")
    #os.system('msiexec /i %s /qn' % 'node_install.msi')
    #subprocess.check_call(["msiexec /i node_install.msi"])
    subprocess.Popen('node_install.msi')
else:
    wget.download('https://nodejs.org/dist/v12.15.0/node-v12.15.0-x86.msi', 'node_install.msi')
    logger.info("We will try now to install NodeJS 32Bits. Please follow the installation process.")
    #os.system('msiexec /i %s /qn' % 'node_install.msi')
    #subprocess.check_call(["msiexec /i node_install.msi"])
    subprocess.Popen('node_install.msi')

Does anyone already succeed in installing an MSI from a python script?

Upvotes: 3

Views: 1005

Answers (1)

AntonK
AntonK

Reputation: 1310

subprocess.check_call accepts a kind of vector, so you should call it this way: subprocess.check_call(["msiexec", "/i", "node_install.msi"])

Upvotes: 0

Related Questions