Enable Installation of Python Package with System lib in a Virtual Environment (#9349)

This commit is contained in:
Oliver Holworthy 2023-07-04 22:46:17 +01:00 committed by GitHub
parent bb2de1fd5d
commit 6c9c8a9001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 6 deletions

View File

@ -255,3 +255,44 @@ jobs:
shell: bash -l {0} shell: bash -l {0}
run: | run: |
pytest -s -v -rxXs --durations=0 ./tests/test_distributed/test_with_spark pytest -s -v -rxXs --durations=0 ./tests/test_distributed/test_with_spark
python-system-installation-on-ubuntu:
name: Test XGBoost Python package System Installation on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install ninja
run: |
sudo apt-get update && sudo apt-get install -y ninja-build
- name: Build XGBoost on Ubuntu
run: |
mkdir build
cd build
cmake .. -GNinja
ninja
- name: Copy lib to system lib
run: |
cp lib/* "$(python -c 'import sys; print(sys.base_prefix)')/lib"
- name: Install XGBoost in Virtual Environment
run: |
cd python-package
pip install virtualenv
virtualenv venv
source venv/bin/activate && \
pip install -v . --config-settings use_system_libxgboost=True && \
python -c 'import xgboost'

View File

@ -259,7 +259,7 @@ There are several ways to build and install the package from source:
import sys import sys
import pathlib import pathlib
libpath = pathlib.Path(sys.prefix).joinpath("lib", "libxgboost.so") libpath = pathlib.Path(sys.base_prefix).joinpath("lib", "libxgboost.so")
assert libpath.exists() assert libpath.exists()
Then pass ``use_system_libxgboost=True`` option to ``pip install``: Then pass ``use_system_libxgboost=True`` option to ``pip install``:

View File

@ -132,8 +132,8 @@ def locate_or_build_libxgboost(
if build_config.use_system_libxgboost: if build_config.use_system_libxgboost:
# Find libxgboost from system prefix # Find libxgboost from system prefix
sys_prefix = pathlib.Path(sys.prefix).absolute().resolve() sys_base_prefix = pathlib.Path(sys.base_prefix).absolute().resolve()
libxgboost_sys = sys_prefix / "lib" / _lib_name() libxgboost_sys = sys_base_prefix / "lib" / _lib_name()
if not libxgboost_sys.exists(): if not libxgboost_sys.exists():
raise RuntimeError( raise RuntimeError(
f"use_system_libxgboost was specified but {_lib_name()} is " f"use_system_libxgboost was specified but {_lib_name()} is "

View File

@ -27,7 +27,7 @@ def find_lib_path() -> List[str]:
os.path.join(curr_path, os.path.pardir, os.path.pardir, "lib"), os.path.join(curr_path, os.path.pardir, os.path.pardir, "lib"),
# use libxgboost from a system prefix, if available. This should be the last # use libxgboost from a system prefix, if available. This should be the last
# option. # option.
os.path.join(sys.prefix, "lib"), os.path.join(sys.base_prefix, "lib"),
] ]
if sys.platform == "win32": if sys.platform == "win32":
@ -62,8 +62,8 @@ def find_lib_path() -> List[str]:
+ ("\n- ".join(dll_path)) + ("\n- ".join(dll_path))
+ "\nXGBoost Python package path: " + "\nXGBoost Python package path: "
+ curr_path + curr_path
+ "\nsys.prefix: " + "\nsys.base_prefix: "
+ sys.prefix + sys.base_prefix
+ "\nSee: " + "\nSee: "
+ link + link
+ " for installing XGBoost." + " for installing XGBoost."