API

Installer

class condansis.Installer(package_name: str, package_root: str | Path, package_version: str = None, installer_name: str | Path = None, default_install_dir: str | Path = None, include: Sequence[str | Path] = None, icon: str | Path = None, postinstall_python_scripts: Sequence[str] = None, preuninstall_python_scripts: Sequence[str] = None, env_file: str | Path = None, env_name: str = None, install_root_package: bool = True, nsis_template: str | Path = None, clean_instdir: bool = False, register_uninstaller: bool = True, compressor: str = 'lzma', makensis_exe: str | Path = 'makensis', conda_command: str = 'conda-env')

Defines an installer for a Python package and its environment

Parameters:
package_name: str

Name of the package

package_root: str or Path

Path to the package root

package_version: str (optional)

Version of the package. Default: None

installer_name: str or Path (optional)

Name of the installer to output. Default: install_{package_name}-{package_version}.exe

default_install_dir: str or Path (optional)

Default install directory in target computer. Accepts NSIS variables Default: %USERPROFILE%\package_name

include: list of str or Path (optional)

List of directories and files to be included in the installer. Should be relative to package_root

icon: str or Path (optional)

Path to installer icon, relative to package_root

postinstall_python_scripts: list of str (optional)

List of commands to be run in Python on the target machine after installation. Accepts NSIS variables

preuninstall_python_scripts: list of str (optional)

List of commands to be run in Python on the target machine before uninstall Accepts NSIS variables

env_file: str or Path (optional)

file defining app environment. Default: package_root/environment.yml

install_root_package: bool (optional)

Whether to run pip install package_root. Default: True

env_name: str (optional)

Name of the python environment in the target machine. Default: {package_name}_env

nsis_template: str or Path (optional)

Path to Jinja2 NSIS template to be used. Defaults to the CondaNSIS default script

clean_instdir: bool (optional)

Whether to clean the install directory before installing new files. Default: False

register_uninstaller: bool (optional)

Whether to register the uninstaller to Windows’ “add or remove programs”. Default: True

compressor: ‘zlib’, ‘bzip2’, or ‘lzma’ (optional)

Compression algorithm to use. Default: lzma See here for more information

makensis_exe: str or Path (optional)

Call to the makensis.exe executable. Defaults to “makensis”

conda_command: “conda-env” or “conda” (optional)
Command to install conda environment. Two options are supported:

“conda-env”: uses conda-env, with support for conda YML files (default) “conda”: uses conda, with support for conda-lock and requirements.txt files

create_temp_env(env_prefix: Path) None

Creates a temporary environment

Parameters:
env_prefix: Path

Directory where the environment will be created

pack_temp_env(work_dir: Path, env_prefix: Path, ignore_missing_files: bool = True) None

Runs conda-pack to create the packaged environment and unpack it in the working directory

Parameters:
work_dir: Path

Working directory to create installer

env_prefix: Path

Directory with the conda environment

ignore_missing_files: bool

Ignore that files are missing that should be present in the conda environment as specified by the conda metadata. Default: True

remove_temp_env(env_prefix: Path) None

Removes the temporary environment

Parameters:
env_prefix: Path

Directory with the conda environment

Warning

Often times this function fails to remove some dlls. Investigate further

create_app_dir(work_dir: Path) None

Copies all include_files to the working directory

Parameters:
work_dir: Path

Working directory to create installer

create_nsis_script(work_dir: Path) Path

Creates the NSIS script based on the template

Parameters:
work_dir: Path

Working directory to create installer

Returns:
script_name: path

Path to the processed makensis script

run_nsis(script_name: Path) None

Runs makensis to create the installer

Parameters:
script_name: Path

Path to processed NSIS script

create() None

Creates the installer

add_shortcut(shortcut_name: str | Path, target_file: str | Path, parameters: str = '', icon_file: str | Path = '') None

Adds a new shortcut to be written by the installer

For more information, please see this link

Parameters:
shortcut_name: str or Path

Full path to the shortcut in the target computer. Accepts NSIS variables

target_file: str or Path

Executable target for the shortcut, in target computer. Accepts NSIS variables and

  • $PYTHON: local python interpreter in target machine

  • $PYTHONW: local pythonw.exe interpreter in target machine

  • $ENV: Name of python environment folder in target machine

parameters: str (optional)

Parameters for the execution of target_file. Default: “”

icon_file: str or Path (optional)

path to “.ico” file in target computer

Examples

create a shortcut to the python interpreter in the installation directory

>>> installer.add_shortcut(r"$INSTDIR\\python.lnk", "$PYTHON")

create a shortcut to execute a run_app.py, located in the “scripts” subfolder

>>> installer.add_shortcut(r"$INSTDIR\\app.lnk", "$PYTHON", "$INSTDIR\\scripts\\run_app.py")