Installing scikit-learn is one command. The reason a guide exists at all is the handful of ways that command goes wrong, and the fact that the most common failure is caused by typing the wrong package name.
The command
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install scikit-learn
Three things worth noting. Use a virtual environment — a global install will eventually collide with something. Use python -m pip rather than bare pip if you have several Pythons, because bare pip may belong to a different one than you think. And the package is scikit-learn, with a hyphen.
Verify it landed:
python -c "import sklearn; print(sklearn.__version__)"
You install scikit-learn and import sklearn. That asymmetry catches everyone once.
Errors you will actually hit
| What you see | What it means | Fix |
|---|---|---|
pip install sklearn fails | Wrong package. sklearn is a deprecated stub | Install scikit-learn |
ModuleNotFoundError: sklearn | Installed into a different interpreter | python -m pip install scikit-learn |
| Building wheel ... failed | No prebuilt wheel, pip is compiling from source | Upgrade pip, or use a supported Python version |
numpy.dtype size changed | Binary mismatch between NumPy and scikit-learn | Reinstall both together in a clean env |
SSLError / cert verify failed | TLS inspection on a corporate network | See the proxy section below |
| Killed during install | Out of memory compiling | Use a wheel, or add swap |
The wheel-building one deserves a note, because the error text sends people down the wrong path. If pip is compiling scikit-learn from source, something is wrong with your environment — there are prebuilt wheels for every mainstream platform. Nine times out of ten it means you are on a Python version newer than the wheels support. Waiting for the compile to finish is not the fix; using a supported Python is.
Apple Silicon and Windows
Both are fine now, with one gotcha each.
Apple Silicon. Wheels are native and no longer need Rosetta or Homebrew gymnastics. The failure that persists is running an x86 Python under Rosetta by accident, usually inherited from an old install. Check with python -c "import platform; print(platform.machine())" — you want arm64.
Windows. Works with pip. If you see a compiler error mentioning Visual C++, you are again in the compile-from-source path, and installing Build Tools is treating the symptom. Check your Python version first.
Installing behind a corporate proxy
This is where most enterprise installs actually die, and the error messages are unhelpful about it.
# explicit
pip install --proxy http://user:pass@proxy.company.com:8080 scikit-learn
# or via environment, which pip and most tools respect
export HTTPS_PROXY="http://user:pass@proxy.company.com:8080"
export HTTP_PROXY="$HTTPS_PROXY"
pip install scikit-learn
If your company inspects TLS, the proxy re-signs certificates with its own root, and pip correctly refuses to trust it. You need to supply that root:
pip install --cert /path/to/corporate-root.pem scikit-learn
# or, for everything that uses requests
export REQUESTS_CA_BUNDLE=/path/to/corporate-root.pem
Do not reach for --trusted-host to make the error go away. It disables verification rather than fixing it, and you are installing executable code — that is precisely the wrong place to skip certificate checks. Ask whoever runs the network for the root certificate; they have it ready, because everyone asks.
pip or conda
pip for most work. conda earns its complexity when you need a particular BLAS implementation, are matching CUDA versions, or are on a platform where wheels are unreliable.
The rule that matters more than the choice: do not mix them in one environment. Installing NumPy with conda and scikit-learn with pip is the most reliable way to produce the numpy.dtype size changed error, and the fix is to start the environment again.
One more thing, if scikit-learn is downstream of data you collect yourself: the model is rarely what limits accuracy — the sample is. Data gathered from a single IP tends to be personalised, cached or rate-limited into something unrepresentative, which is a quieter problem than a failed install and a much more expensive one. Our notes on collecting training data cover that side of it.
Frequently asked questions
What is the command to install scikit-learn?
pip install scikit-learn, inside a virtual environment. Note the hyphen - the package is scikit-learn on PyPI but you import it as sklearn, and pip install sklearn installs a deprecated stub that does nothing useful.
Why does pip install sklearn not work?
Because sklearn on PyPI is a placeholder package that exists to redirect people to the real one. It has been deprecated for years and now raises an error on install. The package name is scikit-learn.
How do I install scikit-learn behind a corporate proxy?
Point pip at the proxy with --proxy http://user:pass@host:port, or set the HTTPS_PROXY environment variable. If your company runs TLS inspection you will also need its root certificate, either via pip's --cert flag or by pointing REQUESTS_CA_BUNDLE at it.
Should I use pip or conda?
pip for most projects. conda is worth it when you need a specific BLAS build, are pinning CUDA versions, or are on a platform where wheels are unreliable. Do not mix them in one environment - that is how you end up with a broken NumPy.