patchelf-wrapper

1.2.0 · maintenance · verified Thu Apr 16

patchelf-wrapper is a Python module designed to assist in the installation of the `patchelf` utility for PyPI-hosted Python projects that depend on it. It ensures the `patchelf` binary is available within a project's build environment. The current version, 1.2.0, packages patchelf 0.11. The project's author notes that for end-users, installing `patchelf` via a system package manager is generally recommended over this wrapper.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to locate the `patchelf` binary installed by `patchelf-wrapper` and then execute it via `subprocess` to perform common operations like printing its version or an ELF binary's RPATH.

import subprocess
from patchelf_wrapper.patchelf import find_patchelf_cmd

try:
    patchelf_path = find_patchelf_cmd()
    print(f"Found patchelf at: {patchelf_path}")

    # Example: Print the version of the installed patchelf
    result = subprocess.run([patchelf_path, '--version'], capture_output=True, text=True, check=True)
    print("patchelf version:\n", result.stdout.strip())

    # Example: Print RPATH of an ELF binary (replace 'your_binary' with an actual path)
    # It's important to use a real ELF file for this, or it will error.
    # try:
    #     some_elf_binary = "/bin/ls" # Replace with a test ELF binary path
    #     rpath_result = subprocess.run([patchelf_path, '--print-rpath', some_elf_binary], capture_output=True, text=True, check=True)
    #     print(f"RPATH of {some_elf_binary}: {rpath_result.stdout.strip()}")
    # except FileNotFoundError:
    #     print(f"Warning: Could not find '{some_elf_binary}' to demonstrate RPATH printing.")
    # except subprocess.CalledProcessError as e:
    #     print(f"Error running patchelf on {some_elf_binary}: {e.stderr.strip()}")

except RuntimeError as e:
    print(f"Error: {e}")
except FileNotFoundError:
    print("Error: patchelf binary not found. Ensure patchelf-wrapper is correctly installed.")

view raw JSON →