Class PackageInstaller
Contains methods to install Python libraries.
public class PackageInstaller
- Inheritance
-
PackageInstaller
- Inherited Members
Remarks
You can use the Library installer to install
-
Download the Python packages using pip:
py -m pip download --only-binary=:all: --python-version 34 requests
- Add the downloaded packages (.whl files) as embedded resource to your .Net Framework application.
-
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
stringPath of the package file.
force
boolAlso 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
AssemblyAssembly which contains the package resource.
resourceName
stringName of the resource. This can be a partial name of the resource. For example:
requests-2.21.0-py2.py3-none-any.whl
.force
boolAlso reinstalls the package if it is already installed.
Exceptions
- ArgumentException
Thrown when a resource with
resourceName
is not found
-or- theresourceName
is not a valid module name.