{"id":6364,"library":"find-libpython","title":"find-libpython","description":"find-libpython is a Python library and script designed to robustly locate the `libpython` dynamic shared library associated with the current Python environment. It supports various Python installations, including conda-managed, system-managed, and virtual environments, across Windows, macOS, and Linux. This utility is crucial for projects embedding a Python interpreter or for Python library build systems that need to link against `libpython`. The current version is 0.5.1, released on February 10, 2026, with an active, though irregular, release cadence.","status":"active","version":"0.5.1","language":"en","source_language":"en","source_url":"https://github.com/ktbarrett/find_libpython","tags":["python","libpython","shared library","dynamic library","embedding","build system","cross-platform","linker"],"install":[{"cmd":"pip install find-libpython","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for execution and library functionality.","package":"python","optional":false}],"imports":[{"symbol":"find_libpython","correct":"from find_libpython import find_libpython"}],"quickstart":{"code":"from find_libpython import find_libpython\n\nlib_path = find_libpython()\nif lib_path:\n    print(f\"Found libpython at: {lib_path}\")\nelse:\n    print(\"Could not find libpython for the current environment.\")","lang":"python","description":"This quickstart demonstrates how to import and use the `find_libpython` function to locate the shared library. It returns the path as a string or `None` if not found."},"warnings":[{"fix":"Ensure your Python installation is configured to build shared libraries (e.g., pass `--enable-shared` during Python compilation) if you require dynamic linking.","message":"Python installations (especially custom builds or newer Linux defaults) may produce a *static* `libpython.a` instead of a *shared* `libpython.so` or `.dylib`. `find-libpython` is designed to locate *shared* libraries. If `find_libpython()` returns `None`, it often indicates that the Python interpreter was compiled without `--enable-shared` or similar flags, making `libpython` unavailable for dynamic linking.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `find-libpython` to programmatically identify the correct path, then ensure your application or build system correctly links against it, potentially by configuring system linker paths or using `rpath`.","message":"Relying solely on environment variables like `LD_LIBRARY_PATH` (Linux) or `DYLD_LIBRARY_PATH` (macOS) to make `libpython` discoverable can be brittle and inconsistent, especially in complex deployment scenarios or when embedding Python. While these might offer temporary fixes, system-wide linker configuration (e.g., `ldconfig` on Linux, or correct RPATHs during compilation) provides a more robust solution.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always ensure the correct Python environment is activated before running code that calls `find_libpython` to guarantee it targets the intended interpreter's shared library.","message":"In environments with multiple Python installations (e.g., system Python, Conda, Pyenv, virtual environments), `find-libpython` attempts to find the `libpython` associated with the *currently active* Python interpreter. Issues can arise if the desired Python environment is not properly activated or if the `PATH` variable leads to an unexpected interpreter, causing `find_libpython()` to return an incorrect path or `None`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}