pip install sklearn stops with a deprecation message from a guard package
Fix it fast
Most common cause, 1 of 2Your command or requirements file names sklearn
Use the real project name in commands and in every dependency file.
python -m pip uninstall -y sklearn
python -m pip install scikit-learn
# requirements.txt
scikit-learn>=1.9Short answer
The sklearn name on PyPI is a guard package that has raised an error on every install since 1 December 2023. Current pip reports Getting requirements to build wheel did not run successfully; older pip said python setup.py egg_info did not run successfully. Install scikit-learn instead (1.9.1 needs Python 3.11 or newer) and remove sklearn from every dependency list.
Which cause do you have?
Search your own dependency files for the old name, without matching other projects such as sklearn-pandas. A hit means you asked for sklearn yourself (cause 1); no hit means another package pulls it in (cause 2).
grep -rniE "^[[:space:]]*['\"]?sklearn([[:space:]]*([<>=!~;,'\"]|$))" requirements*.txt setup.py setup.cfg pyproject.toml Pipfile 2>/dev/nullThen find the line you see in this list and open its fix:
What does the error look like?
The 'sklearn' PyPI package is deprecated, use 'scikit-learn'Getting requirements to build wheel did not run successfully.ERROR: Failed to build 'sklearn' when getting requirements to build wheelpython setup.py egg_info did not run successfully.
Cause 1 of 2
Your command or requirements file names sklearn
You seeThe first step finds sklearn in requirements.txt, pyproject.toml or the command you typed
Check
pip install sklearn fails because sklearn is only the import name. The PyPI project is scikit-learn, and the sklearn project is an empty guard package whose setup.py now exits with the deprecation message unless an override variable is set.
python -m pip install --dry-run sklearnFix
Use the real project name in commands and in every dependency file. The import line in your code stays import sklearn.
python -m pip uninstall -y sklearn
python -m pip install scikit-learn
# requirements.txt
scikit-learn>=1.9Verify
The install finishes and the library reports its version.
python -c "import sklearn; print(sklearn.__version__)"Confirmed by raw.githubusercontent.com
Cause 2 of 2
A dependency still declares sklearn
You seeYour own files are clean, yet the deprecation message appears while installing some other package
Check
Older libraries sometimes listed sklearn in their own install requirements. Since the guard package began failing on every install, pip stops whenever it reaches that line, even though you never typed the name. The lines pip prints around Collecting sklearn show which package asked for it.
python -m pip install --dry-run -r requirements.txt 2>&1 | grep -i -B2 sklearnFix
Upgrade or pin that dependency to a release that requires scikit-learn, and report it upstream if none exists. As a last resort the setup script honours an override variable; the stub it then installs declares no dependencies, so list scikit-learn yourself as well.
python -m pip install --upgrade the-dependency
# last resort only
export SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True
python -m pip install -r requirements.txt scikit-learnVerify
The full requirements install completes and import sklearn works in the same environment.
python -m pip check && python -c "import sklearn"Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Add a CI step that fails when sklearn, rather than scikit-learn, appears in any requirements or pyproject file.
- Regenerate lock files only from an input file that names scikit-learn, so a stale sklearn line cannot come back through an old lock.
- On Python 3.10 or older, expect pip to pick an older scikit-learn; 1.9.1 declares Python 3.11 as its minimum.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.