Python for Data Science Setup
From bare Python to a working workspace
A data science environment is Python plus numpy, pandas, matplotlib/scikit-learn and a project layout — managed with venvs or conda so notebooks and pipelines run identically anywhere.
What you will learn
- Create and activate an isolated virtual environment
- Pin dependencies reproducibly
- Start Jupyter and run cells
What is this?
Python alone is not a data science environment: analysis needs numpy, pandas, scipy, matplotlib and scikit-learn, plus a way to isolate them per project. The standard setup is a virtual environment (venv/conda) with pinned requirements, a Jupyter server or IDE for exploration, and a reproducible file layout — the same 'works on any machine' guarantee containers give to apps.
Why do you need it?
- Different projects need different library versions; a shared global site-packages is a time bomb.
- Reproducibility is the whole point: pin versions and anyone (or any pipeline) rebuilds the same stack.
- Notebook exploration + `.py` scripts + pinned env is the canonical DS workflow.
- A broken env is the most common first-hour blocker in any DS course.
Mental model
A per-kitchen pantry vs one communal pantry for a whole building
Virtual environments vs global packages
The building's pantry overwrites everyone's flour; each kitchen with its own shelf of pinned ingredients cooks dependably. venvs give every project its own shelf.
How it works
- python -m venv .venv creates an isolated interpreter + package folder in the project.
- Activating it switches the shell's python/pip to the project's copies.
- pip install pins exact versions; a requirements.txt freezes them for reproducibility.
- Jupyter (jupyter lab) runs notebooks in the same kernel as the venv when installed there.
- conda wraps python itself and native libs, handy when numpy/scipy need compiled binaries.
Anatomy of a reproducible DS setup.
Key commands
python -m venv .venvCreate an isolated environment in .venv.
source .venv/bin/activateActivate it (Windows: .venv\Scripts\activate).
pip install numpy pandas scikit-learnInstall the core stack into the venv.
pip freeze > requirements.txtPin exact installed versions for reproducibility.
jupyter labLaunch the notebook server.
In production
- A data team rebuilds every analysis from requirements.txt in CI so notebooks ran in October still run in March.
- A model-serve platform bundles the exact python+numpy+pandas versions into the serving image from a frozen env.
- An MLOps studio gives every experiment its own conda env recorded in the experiment tracker.
Best practices
- Create a venv per project, not per machine.
- Pin exact versions (==), not ranges, before shipping an analysis.
- Keep notebooks thin: heavy logic lives in .py modules imported by the notebook.
- Commit requirements.txt and the recreate command, not the environment itself.
Common mistakes
- pip install into the base environment, later breaking another project.
- Committing the .venv folder into git.
- Running jupyter from system python while libraries are in the venv → ModuleNotFoundError.
- Using `pip install python` instead of creating a venv (pip isn't a python substitute).
Debugging tips
- 'ModuleNotFoundError in Jupyter but pip shows installed' → the kernel isn't the venv; check which python jupyter runs.
- which python / which pip tells you what interpreter you're addressing.
- python -c 'import pandas; print(pandas.__version__)' from the shell validates the venv.
Interview checkpoint
Hands-on lab
- Create and activate a venv
- Install the core DS stack
- Freeze requirements and validate imports
Build a Reproducible Env
20 min · beginner
Quick quiz
Which command pins your environment's exact versions to a file?
You should commit your .venv folder to git so teammates can copy the environment.