XGBoost "OSError: libxgboost.so: cannot open shared object file" in CI
The xgboost Python wheel ships a compiled libxgboost.so, but the loader cannot find it - usually because a source build produced no library, the file path is wrong, or an incomplete install left the package without its binary.
What this error means
import xgboost fails with "OSError: ... libxgboost.so: cannot open shared object file: No such file or directory" or "Cannot find XGBoost Library in the candidate path".
OSError: /opt/venv/lib/python3.12/site-packages/xgboost/lib/libxgboost.so:
cannot open shared object file: No such file or directoryCommon causes
A source build that did not compile the library
Installing from an sdist without a working CMake/compiler toolchain leaves the Python package without its libxgboost.so.
A partial or corrupted install
An interrupted install or a stale cached wheel left the package directory without the bundled binary.
How to fix it
Reinstall a prebuilt wheel
Force a clean binary install so the bundled library is present.
pip uninstall -y xgboost
pip install --force-reinstall --only-binary=:all: xgboostProvide a toolchain if you must build from source
If no wheel exists for the platform, install CMake and a compiler so the native library actually builds.
sudo apt-get update && sudo apt-get install -y cmake build-essential
pip install --no-binary xgboost xgboostHow to prevent it
- Prefer prebuilt wheels so the native library ships ready.
- Clear the pip cache if an install was interrupted mid-download.
- Add an import smoke test right after install.