From 9a0c9a0619a1a164c504719248a2e34da987f0fe Mon Sep 17 00:00:00 2001 From: Ishaan Radia Date: Wed, 4 Sep 2024 15:14:39 -0400 Subject: [PATCH 1/2] Made lib paths configurable via environment variable --- doc/build.rst | 13 +++++++++++++ python-package/xgboost/libpath.py | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/doc/build.rst b/doc/build.rst index 6be864587818..44c103a542ca 100644 --- a/doc/build.rst +++ b/doc/build.rst @@ -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:: diff --git a/python-package/xgboost/libpath.py b/python-package/xgboost/libpath.py index 92d46a0bb77d..15ae5d2ae5a3 100644 --- a/python-package/xgboost/libpath.py +++ b/python-package/xgboost/libpath.py @@ -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 @@ -30,6 +33,9 @@ def find_lib_path() -> List[str]: os.path.join(sys.base_prefix, "lib"), ] + if "XGBOOST_LIBRARY_PATH" in os.environ: + dll_path.extend([os.path.join(os.environ.get("XGBOOST_LIBRARY_PATH"), "lib")]) + if sys.platform == "win32": # On Windows, Conda may install libs in different paths dll_path.extend( From ccebd654fe8e0a5b313bd0a9176df23e1a19fe1d Mon Sep 17 00:00:00 2001 From: Ishaan Radia Date: Wed, 4 Sep 2024 16:16:46 -0400 Subject: [PATCH 2/2] Made lib paths configurable via environment variable --- python-package/xgboost/libpath.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python-package/xgboost/libpath.py b/python-package/xgboost/libpath.py index 15ae5d2ae5a3..01049f9af4ae 100644 --- a/python-package/xgboost/libpath.py +++ b/python-package/xgboost/libpath.py @@ -33,8 +33,9 @@ def find_lib_path() -> List[str]: os.path.join(sys.base_prefix, "lib"), ] - if "XGBOOST_LIBRARY_PATH" in os.environ: - dll_path.extend([os.path.join(os.environ.get("XGBOOST_LIBRARY_PATH"), "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