How do I deploy a Python script?

ImportantThe following article uses options that are available starting with the Professional edition and project type.

In this article, you will learn how to deploy and run a Python script on a Windows 10, 64-bit machine that doesn’t have Python installed.

Adding the Python script

Include your Python script as a resource in the Files and Folders page.

Import results

Python as a prerequisite

We will assume that we want to deploy only on a 64-bit machine and run the Python installer silently.

1. Download the latest version of Python from the website. We will use the Windows 64-bit executable installer

2. Go to the Prerequisites page in your Advanced Installer project.

3. Select the Pre-install section so that your prerequisite will install during this step.

4. Press “New Package Prerequisite” from the top-bar.

5. Select the Python executable installer from your disk and press “Open”.

6. Go to the “Setup Files” tab of your newly added prerequisite.

Import results

7. Write the code below in the “Full UI” field, so that the Python installer runs silently.

/quiet InstallAllUsers=1 PrependPath=1 Include_test=0

8. Go to the “Install Conditions” -> “Supported Windows Versions”, uncheck “32-bit Windows versions”.

9. Expand the “64-bit Windows versions” and check what Windows version you want to target.

10. In “Install Conditions” section, enable “Install prerequisite based on conditions”.

11. Create a new criteria by pressing New ->Criteria -> Registry key exists.

12.Write in the “Registry key” field, the registry key of the Python launcher; this will check with PyLauncher exists on the PC and install or don’t install the prerequisite depending on the result.


Python registry search

13. Remove the “File version” criteria from the list.

Checking the prerequisite

We want to make sure the prerequisite was installed correctly before running our custom action.

1. Go to the Search page.

2. Press New Search in the top-bar and follow the search wizard.

3. Select “Search for a registry value”.

4. Write in the “Key” the value below, to check if Python launcher exists.


5. Write [~] in the “Value” field.

6. Leave the interpretation to “Retrieve the raw value”.

Import results

Check "Test your search now" and press Finish.

If you have the Python launcher installed, the search result is "C:\WINDOWS\py.exe".

Running the Python script

We want to run the Python script at the end of the installation. To achieve this, we will use a PowerShell custom action that will launch your script.

1. Go to the Custom Actions page.

2. Create a “Run PowerShell inline script” custom action.

3. Move it below the “Finish Execution” stage; this will turn the “Execution Time” to Immediately.

4. Add the following commands in your custom action:

$scriptPath =  AI_GetMsiProperty APPDIR
$scriptPath = $scriptPath + ""
start-process $scriptPath

The code will set the $scriptPath variable to the APPDIR value(application folder) and concatenate it with the name of your script. Afterwards, it will run the file set in the $scriptPath variable.

5. Leave enabled only the “Install” option in the Execution Stage Condition, so that your script runs only during this stage.

6. Set the “Condition” to the value below, to check if “RESULT_PROPERTY” contains the correct path for the Python launcher, before launching your Python script.


Import results