Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made lib paths configurable via environment variable #10802

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ There are several ways to build and install the package from source:
cd python-package
pip install . --config-settings use_system_libxgboost=True

5. Set custom ``libxgboost.so`` directory via ``XGBOOST_LIBRARY_PATH`` environment variable.

For certain use cases, the system path (``sys.base_prefix``) may not correctly locate the
``libxgboost.so`` shared library. Users can specify a custom directory where ``libxgboost.so``
is located by setting the ``XGBOOST_LIBRARY_PATH`` environment variable.

To configure this, set the environment variable as follows:

.. code-block:: bash

export XGBOOST_LIBRARY_PATH="/path/to/xgboost/build/"

**Important**: Do not include the `/lib/` suffix in the XGBOOST_LIBRARY_PATH value. It will be automatically appended.

.. note::

Expand Down
7 changes: 7 additions & 0 deletions python-package/xgboost/libpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class XGBoostLibraryNotFound(Exception):
def find_lib_path() -> List[str]:
"""Find the path to xgboost dynamic library files.

Supports use of XGBOOST_LIBRARY_PATH environment variable as a
a custom directory for dynamic library file location.

Returns
-------
lib_path
Expand All @@ -30,6 +33,10 @@ def find_lib_path() -> List[str]:
os.path.join(sys.base_prefix, "lib"),
]

custom_xgboost_path = os.environ.get("XGBOOST_LIBRARY_PATH")
if custom_xgboost_path is not None:
dll_path.extend([os.path.join(custom_xgboost_path, "lib")])

if sys.platform == "win32":
# On Windows, Conda may install libs in different paths
dll_path.extend(
Expand Down
Loading