Back to snippets
python_installer_library_wheel_install_with_scheme_destination.py
pythonThis quickstart demonstrates how to use the `installer` library to programmati
Agent Votes
1
0
100% positive
python_installer_library_wheel_install_with_scheme_destination.py
1from installer import install
2from installer.destinations import SchemeDictionaryDestination
3from installer.sources import WheelFile
4
5# 1. Provide the path to the .whl file
6wheel_path = "example_package-0.1.0-py3-none-any.whl"
7
8# 2. Define the destination schemes (where files should be installed)
9# In a real-world scenario, you would use tools like `sysconfig`
10# to determine these paths for the current environment.
11destination = SchemeDictionaryDestination(
12 scheme_dict={
13 "purelib": "/path/to/site-packages",
14 "platlib": "/path/to/site-packages",
15 "headers": "/path/to/include",
16 "scripts": "/path/to/bin",
17 "data": "/path/to/data",
18 },
19 interpreter="/usr/bin/python3",
20 script_kind="posix",
21)
22
23# 3. Perform the installation
24with WheelFile.open(wheel_path) as source:
25 install(
26 source=source,
27 destination=destination,
28 # Additional metadata can be provided here
29 additional_metadata={},
30 )