How to Create and Test an MSIX for a Python Application

Written by Alex Marin · January 10th, 2022

Python is one of the most widely used programming languages, due to its versatility. In a previous article, we covered how to create an MSI for a Python application, where we first converted the Python into an exe and then created an MSI for that Python executable.

This time around, we'll create an MSIX package for a Python application.

Our goal here is to tell our MSIX to automatically download the Python prerequisite and install it – and then, we'll see how to start the Python script.

Creating an MSIX package for your Python application

For this operation, you need to create an MSIX. If you want to review our step-by-step guide on how to create your MSIX package, you can check it out here.

In this example, our Python application is a simple test.py script that outputs a basic GUI to the user.

Python app

To get that, we launched Advanced Installer, created a new MSIX project from scratch, navigated to the Files and Folders page and added our test.py script.

NoteAs we all know, MSIX packages don't support starting any type of file other than an executable file (exe). However, Advanced Installer includes the option to declare a .BAT file as an application target, which allows us to run our Python script.

Then, we created a simple .bat file (with hardcoded paths) and inserted the following lines:

@echo off
python "C:\Program Files\WindowsApps\YourCompany.YourApplication_1.0.0.0_x64__r21n0w1rc5s2y\test.py"

We're using this location as an example, but you can modify the location where test.py will be installed in the BAT file.

Our file was added near the test.py script in our MSIX package like this:

Python File in Advanced Installer

Then, we can follow these steps:

  1. Navigate to the Application Details Page,
  2. Select that the Application is compiled
  3. Choose the previously added BAT file.
  4. At the end, it should look something like this:
Application Details BAT file

How to Add a Python dependency into an MSIX package?

Now that the package contains our python scripts and our .BAT file – which lets us run the scripts – we will need to consider adding Python as a dependency.

There are different versions of Python in the Microsoft Store, so you will need to choose the one that works for you:

Python dependency Microsoft Store

In this example, we selected Python 3.8 as a dependency, but the steps are identical no matter the version.

Once we've done that, we have to tell our MSIX package to automatically install the Python dependency. Here's how to do that:

  1. Navigate to the Dependencies Page to declare our Python dependency.
  2. Select New Dependency
  3. Add all the details of the Python package manually.

To get all the details of the dependency, we can install Python 3.8 from the Microsoft Store. Then, with the Get-AppPackage PowerShell cmdlet, we can get all the necessary details of the Python package.

Python app details

As you can see, the name of the MSIX package is PythonSoftwareFoundation.Python.3.8, the Publisher is CN=4975D53F-AA7E-49A5-8B49-EA4FDC1BB66B, the minimum version is 3.8.2800.0, and the architecture is X64.

When we click on New Dependency in Advanced Installer, this is how the details look :

Edit package dependency in Advanced Installer

Since we want the prerequisite to be installed automatically, we didn't check the Optional checkbox.

In the end, the declaration should look like this:

Python declaration Advanced Installer

For more details about MSIX dependencies, check out MSIX Applications: Handle Prerequisites by Declaring Dependencies in MSIX.

How to Test the MSIX Package for your Python Application?

Now that we have our MSIX package created, we should see that the step “Installing Required Frameworks” appears when we start the installation:

Install MSIX Python

This means that our dependency declaration worked! Now, when you install your application, the Python 3.8 dependency is automatically downloaded and installed from the Microsoft Store.

Python Dependency Downloaded and Installed

NoteThis only works for dependencies that are listed in the Microsoft Store.

As a result, when you launch the application, the script should execute successfully, as seen below:

Python app

Conclusion

Since MSIX does not natively support the possibility of running types of files other than EXE, this operation was harder to implement in the past. But, the Package Support Framework overcomes this limitation making it easier to implement workarounds.

When the Python MSIX package is installed, it creates an AppExecutionAlias that lets you call python.exe from CMD or other utilities, basically acting like an Environment Variable.

Combined with the easy to use GUI of Advanced Installer and the capability of MSIX to automatically download prerequisites from the Microsoft Store, it’s now very easy to create an MSIX package for your Python scripts and push them to your users.

Comments: