ImportError: cannot import name 'concat' from 'lightgbm.compat'
Third-person routing text. Fixes ImportError for concat from lightgbm.compat: a version-mismatch symptom where installed files do not match. Reinstall lightgbm cleanly so all modules come from one version. Use when an agent hits this importing lightgbm. Not for user code.
TL;DR: your lightgbm install is a mix of versions from a partial upgrade. Reinstall lightgbm cleanly so every module comes from one version.
The error
ImportError: cannot import name 'concat' from 'lightgbm.compat'Fix it
Uninstall lightgbm fully:
pip uninstall -y lightgbmExpected: reports removal.
- Check for leftover lightgbm folders in site-packages and delete them by hand.
Install fresh:
pip install lightgbmExpected: install completes.
Verify:
python -c "import lightgbm; print(lightgbm.__version__)"Expected: prints the version, no error.
When this applies
Use this when import lightgbm itself raises the concat error, which signals mixed install files rather than a real API problem.
When it does not apply
If your own code imports from lightgbm.compat, stop; it is a private module. If the error appears only in one project, check for a vendored lightgbm copy shadowing the install.
Compatibility
Any lightgbm version; this is an install-hygiene issue, not a version issue.
Root cause
lightgbm.compat is a private compatibility module whose contents change between releases. A partial upgrade (or pip and conda both installing lightgbm) leaves old and new files side by side, and the mismatched modules cannot import each other's names.
Edge cases
If pip and conda both manage the env, pick one installer for lightgbm and uninstall the other copy. In docker, pin the lightgbm version so rebuilds stay consistent.