How to Install xgboost in Python
XGBoost Python Package
pip install xgboost
What is xgboost?
XGBoost Python Package
For a stable version, install using ``::
Quick Start
Minimal example to get started with xgboost:
import xgboost
print(xgboost.__version__)
Installation
pip (standard)
pip install xgboost
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install xgboost
pip3
pip3 install xgboost
conda
conda install -c conda-forge xgboost
Poetry
poetry add xgboost
Dependencies
Installing xgboost will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import xgboost; print(xgboost.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing xgboost with pip.
ModuleNotFoundError: No module named 'xgboost'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install xgboost. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'xgboost' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install xgboost to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'xgboost'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show xgboost and upgrade with pip install --upgrade xgboost.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install xgboost. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user xgboost
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org xgboost
RuntimeError: CUDA out of memory
Cause: Model or batch size exceeds GPU memory.
Fix: Reduce batch size, call torch.cuda.empty_cache(), or run on CPU.
Recent Releases
| Version | Released |
|---|---|
3.2.0 latest |
2026-02-10 |
3.1.3 |
2026-01-10 |
3.1.2 |
2025-11-20 |
3.1.1 |
2025-10-21 |
3.1.0 |
2025-10-17 |
Manage xgboost
Upgrade to latest version
pip install --upgrade xgboost
Install a specific version
pip install xgboost==3.2.0
Uninstall
pip uninstall xgboost
Check what is installed
pip show xgboost