Setting Up a Data Science Environment

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Every data science project starts with the same question: which Python, with which versions of NumPy, pandas, scikit-learn and friends, installed how, and isolated from what? A wrong answer rarely fails loudly. It shows up three months later as "it worked on my laptop", a notebook that cannot be rerun, or a model whose numbers drift after an upgrade. This page covers the part of environment management that is specific to data science. Examples target Python 3.13 or 3.14 and were run on Python 3.13. They used NumPy 2.5, pandas 3.1 and scikit-learn 1.9, the versions this page targets, and every statement was checked in October 2026. NumPy 2.5 needs Python 3.12 or later.

The general mechanics of virtual environments, pip and lock files are documented elsewhere on this site and are not repeated here: see Virtual Environments and Packaging, Environments and Externally Managed Pythons, Lock Files and Reproducible Installs and Choosing and Migrating Between Build Tools. This page adds what those pages do not need to say: conda and Miniforge, running uv with Jupyter, binary wheels and BLAS, and the version policy of the scientific Python projects.

Three ways to build an environment

There is no single best tool. There are three mainstream choices, and the right one depends on what the project needs beyond pure Python packages.

Approach Best for Strengths Limits

venv + pip

Learning, small projects, anything that only needs wheels from PyPI.

Ships with Python, nothing extra to install, understood by every tool and CI system.

Only installs Python packages, never the interpreter itself or system libraries. No lock file unless you add one (pip freeze, pip-tools, or pip’s lock support).

uv

Most new projects that live on PyPI: fast installs, a lock file, managed interpreters, one tool for scripts and projects.

Installs and pins Python itself, creates pyproject.toml and uv.lock, resolves for all platforms, runs tools without installing them (uv run).

Same PyPI-only scope as pip: a package that needs a compiled non-Python library with no wheel must be built by you.

Miniforge (conda + conda-forge)

Projects that need compiled native libraries beyond wheels (GDAL, HDF5, CUDA toolkits, R next to Python), or a choice of BLAS implementation.

Installs interpreters and native libraries from one solver, a single binary channel (conda-forge) with a consistent build matrix.

A second ecosystem to learn; mixing in pip install can break the environment’s consistency; channel and licence rules (below).

flowchart TD A["New data science project"] --> B{"Everything you need available as PyPI wheels?"} B -- Yes --> C{"Want one tool that also pins Python and a lock file?"} C -- Yes --> D["uv: pyproject.toml + uv.lock"] C -- No --> E["python -m venv + pip"] B -- "No: native libraries, GPU toolkits, R" --> F{"Employer larger than 200 people?"} F -- Yes --> G["Miniforge with conda-forge only (never the Anaconda defaults channel)"] F -- No --> H["Miniforge, or Anaconda if you accept its terms"] G --> I["Keep pip usage minimal and record it"] H --> I

The diagram above is a starting point, not a rule. Many teams use uv for application and analysis projects and Miniforge only on the few machines that need a native stack.

Which Python version to target

A data science environment is only as old as its oldest package. The scientific Python projects coordinate their support windows through SPEC 0 ("Minimum Supported Dependencies"): a Python version is supported for 36 months after its release, and the core scientific packages for 24 months after theirs. Projects that follow the policy drop old versions together, which means that a very old Python quickly stops receiving new releases of NumPy, SciPy, pandas or scikit-learn.

Package Minimum version at the end of 2026 under SPEC 0 Notes

Python

3.13

3.12 is dropped in the 2026 Q4 cycle. Python 3.15 was released on 2026-10-09 (3.15.2 was current when this page was written); give new libraries a few months before moving production work.

NumPy

2.3

NumPy 2.5 is the version covered by this section.

Matplotlib

3.11

Matplotlib 3.11 requires Python 3.11 or newer.

scikit-learn

1.7

scikit-learn 1.9 is covered by this section.

SciPy

1.15

Stays at 1.15 until 2027 Q1.

pandas

2.3

Stays at 2.3 until 2027 Q2. pandas 3.1 is covered by this section.

The practical reading: choose the newest Python that all of your libraries already publish wheels for. For this section that means any Python from 3.12 upward works, and 3.13 is a safe default. A package that is not yet available for the newest Python is a signal to wait, not to compile it yourself. Free-threaded Python builds (without the global interpreter lock) are supported only experimentally by NumPy since 2.1, so do not use them for analysis work yet.

Plain venv and pip

For a quick project nothing beats the standard library. Create the environment inside the project directory, activate it, and install the stack:

python3 -m venv .venv
source .venv/bin/activate          # Windows PowerShell: .venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install numpy pandas scikit-learn matplotlib seaborn scipy jupyterlab
python -m pip freeze > requirements.txt

Three habits avoid most trouble. Always call python -m pip rather than a bare pip, so the installer belongs to the interpreter you think it does. Never install into the system Python (many Linux distributions and Homebrew mark it "externally managed" and refuse, see Environments and Externally Managed Pythons). And treat pip freeze output as a snapshot of what happened to be installed, not as a declaration of what the project needs: it mixes direct and transitive dependencies and has no hashes.

uv for data science projects

uv manages interpreters, environments, dependencies and a lock file with one command-line tool. A new analysis project:

uv init --python 3.13 churn-analysis
cd churn-analysis
uv add numpy pandas scikit-learn matplotlib seaborn
uv add --dev jupyterlab ipykernel
uv run python -c "import pandas; print(pandas.__version__)"

Source: uv documentation.

uv add edits pyproject.toml and updates uv.lock; uv run guarantees the command runs inside the project environment, re-syncing it first if the lock changed. Commit both files. Anyone (or any CI job) who clones the project then reproduces the environment with uv sync. For scripts that are not part of a project, uv can run a tool with extra packages for a single invocation, which is how you can try something without touching any environment:

uv run --with pandas --with pyarrow python -c "import pandas as pd; print(pd.__version__)"

Source: uv documentation.

Using uv together with Jupyter has two modes and one well-known gotcha, described on the Jupyter Notebooks & JupyterLab page: uv run --with jupyter jupyter lab starts a server whose default kernel already sees the project’s packages, a separately installed Jupyter (for example one started with uv tool run jupyter lab) needs the project registered as a named kernel, and %pip install inside a notebook changes the environment without updating pyproject.toml or uv.lock.

Miniforge and conda-forge

conda is a package manager for any kind of software, not only Python. It solves for an interpreter, Python packages and the native libraries beneath them together, and installs prebuilt binaries from a channel. A channel is a package repository with its own build policy. Two large ones matter for data science: Anaconda’s defaults channel and the community-run conda-forge. They are built differently and must not be mixed.

Anaconda’s terms of service, updated on 2025-07-15, restrict the use of Anaconda’s own repository (the defaults channels and the Anaconda Distribution installer’s default configuration). In summary: individuals using it for personal, non-commercial purposes and eligible academic and non-profit organisations may use it free of charge, while a for-profit organisation with more than 200 employees or contractors, counting affiliates, needs a paid plan. Packages on conda-forge are a separate matter: they are published by the community under their own open-source licences and the terms above do not apply to them. This is a summary, not legal advice, and the terms can change, so read them on Anaconda’s site and ask your organisation’s counsel if you are unsure.

The simplest way to stay on the safe side is Miniforge, the community installer that provides conda and mamba with conda-forge as the only configured channel:

# macOS and Linux
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh
# Windows: download and run Miniforge3-Windows-x86_64.exe from the same releases page

Source: Miniforge (conda-forge/miniforge). For unattended installs such as CI, pass -b to the shell installer.

Creating and using a conda environment

conda create --name churn python=3.13 numpy pandas scikit-learn matplotlib seaborn jupyterlab
conda activate churn
conda list --show-channel-urls | head
conda env export --from-history > environment.yml

Source: conda documentation. --from-history writes only what you asked for, instead of every transitive package with its platform-specific build string, so the file stays portable. A hand-written environment.yml is the conda counterpart of pyproject.toml:

name: churn
channels:
  - conda-forge
dependencies:
  - python=3.13
  - numpy=2.5
  - pandas=3.1
  - scikit-learn=1.9
  - jupyterlab
  - pip
  - pip:
      - some-package-only-on-pypi

conda-forge and defaults are incompatible

The conda-forge documentation states that, since 2024, co-installing packages from Anaconda’s channel and from conda-forge in the same environment is no longer supported: the two channels build the same package names against different toolchains, so a mixed environment can contain binaries that do not agree with one another. If you did not start from Miniforge, configure the environment once and then verify it:

conda config --env --add channels conda-forge
conda config --env --remove channels defaults
conda config --env --set channel_priority strict
conda list --show-channel-urls

Source: Transitioning from defaults (conda-forge). With channel_priority strict, conda takes a package from the highest-priority channel that has it instead of picking the newest build anywhere, which is what keeps the environment consistent. In the output of the last command, every package should come from conda-forge. A package installed by pip may appear with a PyPI source: that is expected, but it is also where inconsistency enters.

Mixing conda and pip

Rules of thumb that keep conda environments healthy: install everything you can with conda first, install the remainder with python -m pip install last, and never run conda install again afterwards in the same environment without being ready to rebuild it. Record the pip packages in the pip: section of environment.yml. If an environment gets into a state nobody understands, delete it and recreate it from the file: environments are meant to be disposable.

Binary wheels, BLAS and threads

NumPy, SciPy, pandas, scikit-learn and Matplotlib all contain compiled code. When you pip install them, you normally get a wheel: a prebuilt binary for your operating system, CPU architecture and Python version. If no wheel exists (a very new Python, an unusual platform), pip falls back to building from source, which needs compilers and can take minutes or fail. Check the build on the page of the package and prefer waiting for wheels.

Linear algebra in NumPy and SciPy is delegated to a BLAS/LAPACK library. PyPI wheels bundle OpenBLAS on Linux and Windows, while NumPy’s PyPI wheels for macOS 14 or later are built against Apple’s Accelerate instead. Miniforge lets you choose between OpenBLAS, MKL and, on Apple Silicon, Accelerate. The choice affects speed and the number of threads used, not results beyond normal floating-point differences. To see what an installation uses, and to limit the threads, use threadpoolctl, which scikit-learn already depends on. threadpoolctl detects OpenBLAS, MKL, BLIS and OpenMP, but not Accelerate: on macOS with Accelerate it lists no BLAS at all, and np.show_config() is the way to see which BLAS NumPy was built against (the Build Dependencies section names accelerate, openblas or mkl).

import sys
from importlib.metadata import version

import numpy as np
import pandas as pd
import sklearn
from threadpoolctl import threadpool_info

print("Python      ", sys.version.split()[0], "at", sys.executable)
for name in ("numpy", "pandas", "scikit-learn", "scipy", "matplotlib"):
    print(f"{name:<12}", version(name))

# which BLAS does NumPy use, and how many threads?
for lib in threadpool_info():
    print(lib["internal_api"], lib.get("version"), "threads:", lib["num_threads"])

# a quick sanity check that the stack works together
rng = np.random.default_rng(0)
df = pd.DataFrame(rng.normal(size=(5, 2)), columns=["a", "b"])
print(df.describe().loc[["mean", "std"]].round(2))

Source: numpy.show_config and the threadpoolctl documentation. Output on the pinned versions on an Apple Silicon Mac (the thread count and numeric libraries depend on the machine). Only scikit-learn’s OpenMP runtime is listed, because NumPy uses Accelerate there; on Linux or Windows an openblas line appears as well:

Python       3.13.18 at /path/to/.venv/bin/python
numpy        2.5.4
pandas       3.1.0
scikit-learn 1.9.1
scipy        1.18.1
matplotlib   3.11.2
openmp None threads: 10
         a     b
mean  0.17  0.00
std   0.83  0.82

A script like this at the top of a notebook, or pasted in a bug report, answers the first question anyone asks. To cap the BLAS threads for a section of code (useful on shared servers, or when you also run parallel jobs and do not want n_jobs times the number of BLAS threads):

import numpy as np
from threadpoolctl import threadpool_limits

rng = np.random.default_rng(0)
a = rng.normal(size=(500, 500))
with threadpool_limits(limits=1, user_api="blas"):
    b = a @ a
print(b.shape)   # (500, 500)

Source: threadpoolctl. Setting the environment variables OMP_NUM_THREADS or OPENBLAS_NUM_THREADS before Python starts has the same effect for a whole process. Neither works for Accelerate on macOS: threadpool_limits cannot see it, so the block above runs but leaves the BLAS thread count unchanged there.

Registering the environment as a notebook kernel

A Jupyter server and a notebook kernel are separate processes, and the kernel is what imports your packages. The most common "ModuleNotFoundError in a notebook that works in the terminal" cause is a kernel that points at a different environment. With uv, conda or venv, the environment needs ipykernel installed and, if the server runs elsewhere, a registered kernel:

# venv or conda environment, activated
python -m ipykernel install --user --name churn --display-name "Python (churn)"
jupyter kernelspec list

Source: Installing the IPython kernel (IPython documentation). The uv-specific variant, which uses --env VIRTUAL_ENV, is in Jupyter Notebooks & JupyterLab.

Reproducibility checklist

  • Pin the interpreter minor version (requires-python in pyproject.toml, or python=3.13 in environment.yml).

  • Commit the lock file (uv.lock) or an explicit, minimal environment.yml, and the notebook-independent code that reads it.

  • Keep one environment per project. Do not reuse a "base" environment, and never install into it.

  • Record versions in the output of every report or experiment: the script above is enough.

  • Seed every random generator you use (see Reproducibility & MLOps Basics).

  • Upgrade on purpose, not by accident: read the release notes of NumPy, pandas and scikit-learn before bumping a major or minor version, since each of them removes APIs that older tutorials still use.

Older advice Status in 2026

"Install Anaconda; it is the way to do data science."

Anaconda is still a valid product, but its terms changed in 2025 for larger companies, and Miniforge with conda-forge or uv with PyPI wheels are the common free alternatives. Notes of this kind written before 2024 predate the conda-forge position on mixing channels.

“pip install into the base environment or the system Python.”

For a system Python, modern Linux distributions and Homebrew mark the interpreter as externally managed (PEP 668), and pip refuses with "externally-managed-environment". conda’s base environment is not marked that way, so pip still installs there, but it mixes pip packages into the environment that runs conda itself and can break it. In both cases, use a project environment.

“pip install sklearn.”

The sklearn package name on PyPI was deprecated for years and now fails. Install scikit-learn; it is imported as sklearn.

For choosing among the notebook tools, see Python IDEs and Tools. The next step after the environment is working is Jupyter Notebooks & JupyterLab and then Data Sources & File Formats.