Table of Contents

Class PackageInstaller

Namespace
Loehnert.Lisrt.Scripting.Python
Assembly
Loehnert.Lisrt.Scripting.dll

Contains methods to install Python libraries.

public class PackageInstaller
Inheritance
PackageInstaller
Inherited Members

Remarks

You can use the Library installer to install Python packages.

  1. Download the Python packages using pip:
    py -m pip download --only-binary=:all: --python-version 34 requests
  2. Add the downloaded packages (.whl files) as embedded resource to your .Net Framework application.
  3. Install the packages:
    var assembly = GetType().Assembly;
    PackageInstaller.InstallWheelFromResource(assembly, "certifi-2021.10.8-py2.py3-none-any.whl");
    PackageInstaller.InstallWheelFromResource(assembly, "chardet-3.0.4-py2.py3-none-any.whl");
    PackageInstaller.InstallWheelFromResource(assembly, "idna-2.8-py2.py3-none-any.whl");
    PackageInstaller.InstallWheelFromResource(assembly, "requests-2.21.0-py2.py3-none-any.whl");
    PackageInstaller.InstallWheelFromResource(assembly, "urllib3-1.24.3-py2.py3-none-any.whl");

Methods

InstallWheel(string, bool)

Installs a Python package from a .whl file.

public static void InstallWheel(string wheelPath, bool force = false)

Parameters

wheelPath string

Path of the package file.

force bool

Also reinstalls the package if it is already installed.

Exceptions

ArgumentException

Thrown when the wheelPath is not a valid module name.

InstallWheelFromResource(Assembly, string, bool)

Installs a Python package from a embedded resource.

public static void InstallWheelFromResource(Assembly assembly, string resourceName, bool force = false)

Parameters

assembly Assembly

Assembly which contains the package resource.

resourceName string

Name of the resource. This can be a partial name of the resource. For example: requests-2.21.0-py2.py3-none-any.whl.

force bool

Also reinstalls the package if it is already installed.

Exceptions

ArgumentException

Thrown when a resource with resourceName is not found
-or- the resourceName is not a valid module name.