Setting up the plugin development environment
This tutorial is written towards beginner/intermediate Python users. Advanced Python users may have preferred methods for development. Consult the "Requirements" section of the "Reference Guide" for a description of the minimum development tools. Additionally, the tutorial assumes usage of a Windows™ operating system.
Plugin development in SAInt requires precise dependency management because a plugin as a standalone program must contain all Python packages. Therefore, it is strongly recommended to use a virtual environment for each plugin you wish to author to ensure that all and only the Python packages needed for that plugin are properly managed. Python virtual environments let you install packages in an isolated workspace, keeping them separate from your system-wide Python installation. They allow for a simple and reproducible management of packages specific to a project. They help preventing version conflicts and work everywhere, even when you have limited rights on a machine.
In this tutorial we use Python’s "venv", but other options are available like "virtualenv", "pipenv", or "pyenv".
1. Install Python
The first thing we need is a working Python installation on your Windows machine. You can do this by downloading Python from the official "Python website" (https://www.python.org/) or by using the Microsoft Store. The Microsoft Store installation is recommended for beginners as it handles the setup of PATH settings and provides automatic updates. We recommend to install Python version 3.14 or 3.13, and avoid the latest version.
To install Python using the Microsoft Store:
-
Open the Microsoft Store from the Start menu.
-
Search for "Python" and select the version you want to install.
-
Click "Get" to download and install Python.
To install from the Python website:
-
Open your browser and navigate to the official Python downloads page (https://www.python.org/downloads/).
-
Select and download the version of Python you prefer for the Windows operating system.
-
Run the downloaded installer by double-clicking the file, and, in the installation wizard, check the box for "Add Python to PATH". Click "Install Now" or choose "Customize Installation" for advanced options. Wait for the installation to complete and click Close.
After installation, you can verify the installation by opening Windows PowerShell and typing:
python --version
or (under Windows) you can use:
py --version
If you do not prefer to download Python to your system, you can use a portable Python installation. It is recommended to use "winpython" (https://winpython.github.io/) downloaded through Github — specifically the dot version which includes a minimal Python installation.
|
We do not recommend to use "conda" (https://conda.org/) to create plugins due to the way it caches dependencies. |
2. Create the Project folder
Each plugin needs its own project folder, which will contain all necessary files and data. Select a location on your computer and create a folder named "violinplot". This will be our project folder.
In "violinplot", create the following two folders:
-
"data": We will save here the test network and scenarios for checking our plugin.
-
"dist": This folder will hold the compiled plugin.
-
"results": We will write our output here.
So the final structure for our project is:
violinplot/
├── data/
├── dist/
├── results/
└── <any other file>
3. Create a virtual environment
The package venv is part of the Python Standard Library (starting with Python 3.3), so there is now need to install it.
To create a virtual environment, go to your project’s directory and run the following command. This will create a new virtual environment in a local folder named .venv:
python -m venv .venv
The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it ".venv". venv will create a virtual Python installation in the newly created ".venv" folder.
|
This virtual environment will be used for this plugin and this plugin only. |
Once the virtual environment is created, it is necessary to tell Python to use it by activating it. When activated, the virtual environment is recognized by the Python interpreter, which will use that isolated environment for the development adn the installation of packages. To activate your virtual environment use:
.venv\Scripts\activate
You should see (.venv) in your terminal. You should now be able to run python in your virtual environment. To confirm the virtual environment is activated, check the location of your Python interpreter:
where python
The command will output a filepath that includes the .venv directory, and ends with .venv\Scripts\python.exe.
Now that the virtual environment is activated, the program pip will install packages only into this specific environment.
Congrats! You have now created a completely isolated virtual Python environment for development!
Now your project’s folder should look like:
violinplot/
├── .venv/
├── data/
├── dist/
├── results/
└── <any other file>
4. Install "PyInstaller"
We will use the package "PyInstaller" to create and distribute our plugin as an application. PyInstaller n is a powerful tool that bundles Python applications and their dependencies into standalone executables. This allows to run a packaged app without installing a Python interpreter or any modules. PyInstaller supports Python 3.8 and newer, and correctly bundles many major Python packages such as numpy, matplotlib, PyQt, wxPython, and others.
Now, in your virtual environment, type the command:
pip install pyinstaller
The basic usage of PyInstaller to create an executable from your Python script is to run:
pyinstaller your_program.py
This generates a "dist" folder containing the executable and required files. But we already have the "dist" folder in our project folder.