{"id":6862,"library":"rpm","title":"RPM Shim for Virtualenvs","description":"The `rpm-shim` library (available on PyPI as `rpm`) provides a shim module to enable the use of system RPM Python bindings within Python virtual environments. This is necessary because native RPM Python bindings are typically tied to the system's RPM installation and are not distributed as standard Python packages. The library is currently at version 0.4.0 and releases are made on an as-needed basis to improve compatibility and search heuristics.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/packit/rpm-shim","tags":["rpm","virtualenv","shim","system bindings","linux"],"install":[{"cmd":"pip install rpm","lang":"bash","label":"Install in virtual environment"}],"dependencies":[],"imports":[{"note":"The `rpm` module is typically imported directly as a top-level module, mirroring the system `rpm` module's usage.","wrong":"from rpm import Something","symbol":"rpm","correct":"import rpm"}],"quickstart":{"code":"import venv\nimport subprocess\nimport sys\nimport os\n\n# Create a dummy virtual environment for demonstration\nvenv_path = './my_rpm_venv'\nif not os.path.exists(venv_path):\n    venv.create(venv_path, with_pip=True)\n\n# Activate the virtual environment and install rpm-shim\n# In a real scenario, you'd activate the venv and then `pip install rpm`\nprint(f\"Installing rpm-shim in {venv_path}...\")\npython_executable = os.path.join(venv_path, 'bin', 'python')\nsubprocess.run([python_executable, '-m', 'pip', 'install', 'rpm'], check=True, capture_output=True)\nprint(\"Installation complete.\")\n\n# Now demonstrate importing and using rpm inside the virtual environment\n# (simulating execution within the venv)\npython_code = \"\"\"\nimport sys\nimport os\n\ntry:\n    import rpm\n    print(f\"Successfully imported rpm from: {rpm.__file__}\")\n    # Example of using rpm (check version as a simple call)\n    print(f\"RPM library version: {rpm.expand_macro('%{_rpm_version}')}\")\nexcept ImportError as e:\n    print(f\"Failed to import rpm: {e}\")\n    print(\"Make sure system RPM Python bindings are installed on your system (e.g., python3-rpm).\")\n\"\"\"\n\nprint(\"\\nRunning rpm import test within the virtual environment...\")\nresult = subprocess.run([python_executable, '-c', python_code], capture_output=True, text=True, check=True)\nprint(result.stdout)\nif result.stderr:\n    print(\"Stderr:\", result.stderr)\n\n# Clean up (optional)\n# import shutil\n# shutil.rmtree(venv_path)\n","lang":"python","description":"This quickstart demonstrates installing `rpm-shim` (as `rpm`) into a virtual environment and then importing and using the `rpm` module. The core idea is that once `rpm-shim` is installed, a simple `import rpm` will make the system's RPM bindings available within your virtual environment. Ensure that your system has the native RPM Python bindings installed (e.g., `python3-rpm` package on RPM-based systems)."},"warnings":[{"fix":"Upgrade to `rpm-shim` version `0.4.0` or newer. This version prioritizes searching for the `rpm` module within the current interpreter's paths, resolving this common issue.","message":"Prior to `0.4.0`, `rpm-shim` might inadvertently pick up the `rpm` module from a different Python interpreter on the system (e.g., a system-wide Python 3.6 module) rather than the `rpm` bindings intended for the currently active virtual environment's Python version.","severity":"gotcha","affected_versions":"<0.4.0"},{"fix":"Ensure that your operating system has the corresponding native Python RPM bindings installed. For most RPM-based Linux distributions, this means installing a package like `python3-rpm` (or `python-rpm` for Python 2) via your system's package manager (e.g., `dnf install python3-rpm` or `zypper install python3-rpm`).","message":"The `rpm-shim` package on PyPI is *not* a standalone Python implementation of RPM functionality. It is a shim that relies on the presence of the native RPM Python bindings installed on the host system. If these bindings are not installed (e.g., the `python3-rpm` package on Fedora/RHEL/openSUSE), `rpm-shim` will fail to import `rpm` with an `ImportError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Only install and use `rpm-shim` within a Python virtual environment where you explicitly need access to the system `rpm` module.","message":"The `rpm-shim` library is specifically for making system RPM bindings available in virtual environments. There is no benefit to installing this shim on a bare system outside a virtual environment, and it could potentially conflict with or overwrite existing native RPM Python bindings if not handled carefully.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}