Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
AI and LLM integration

pip install sklearn stops with a deprecation message from a guard package

Your error

The 'sklearn' PyPI package is deprecated, use 'scikit-learn'3 more lines it can show

Fix it fast

Most common cause, 1 of 2

Your command or requirements file names sklearn

Use the real project name in commands and in every dependency file.

Fix
python -m pip uninstall -y sklearn
python -m pip install scikit-learn

# requirements.txt
scikit-learn>=1.9
Did this fix it?
Full steps for this cause: check, fix, verify

Short 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.

  • Applies to scikit-learn 1.9.1, pip 26.3, Python 3.11 to 3.15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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).

Run this first
grep -rniE "^[[:space:]]*['\"]?sklearn([[:space:]]*([<>=!~;,'\"]|$))" requirements*.txt setup.py setup.cfg pyproject.toml Pipfile 2>/dev/null

Then find the line you see in this list and open its fix:

  1. 1Your command or requirements file names sklearnThe first step finds sklearn in requirements.txt, pyproject.toml or the command you typed
  2. 2A dependency still declares sklearnYour own files are clean, yet the deprecation message appears while installing some other package

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 wheel
  • python 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.

Check
python -m pip install --dry-run sklearn

Fix

Use the real project name in commands and in every dependency file. The import line in your code stays import sklearn.

Fix
python -m pip uninstall -y sklearn
python -m pip install scikit-learn

# requirements.txt
scikit-learn>=1.9

Verify

The install finishes and the library reports its version.

Verify
python -c "import sklearn; print(sklearn.__version__)"

Confirmed by raw.githubusercontent.com

Did this fix it?

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.

Check
python -m pip install --dry-run -r requirements.txt 2>&1 | grep -i -B2 sklearn

Fix

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.

Fix
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-learn

Verify

The full requirements install completes and import sklearn works in the same environment.

Verify
python -m pip check && python -c "import sklearn"

Confirmed by raw.githubusercontent.com

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.