Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 3/ 160
01. Python & Data Wrangling

Virtual Environments & Git Version Control

Isolate project dependencies with venv/conda and track experiments safely with Git workflows.

Beginnervenv/conda · Git Basics3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

A virtual environment keeps each project's tools in its own box, and Git keeps a saved history of every change so you can go back.

Think of it like…

A lab notebook with separate labelled boxes of equipment: each experiment has its own box of tools (the environment) so nothing contaminates anything else, and the notebook pages are dated and never torn out (the Git history).

Where you’ve seen it

A forecasting model gives different numbers on a colleague's laptop. pip freeze shows they have numpy 2.1 and statsmodels 0.13, while the original environment used numpy 1.26 and statsmodels 0.14. The team adds a pinned requirements.txt (or a lock file), a README with the setup commands, and a Git tag for the release that produced the reported numbers, so anyone can recreate the exact run.

Words you’ll hear

Virtual environment
An isolated set of installed packages tied to one project.
requirements.txt / lock file
A list of exact package versions needed to recreate the environment.
Commit / branch
A saved snapshot of changes / a parallel line of work that can be merged.
.gitignore
A list of files Git should not track, such as data, secrets and environments.

Visual diagram

Loading interactive diagram

Theory & deep dive

Environments in practice

Create one environment per project: python -m venv .venv, activate it (source .venv/bin/activate or .venv\Scripts\activate on Windows), then pip install pandas scikit-learn. Save exact versions with pip freeze > requirements.txt, and recreate them with pip install -r requirements.txt. For tighter control, tools such as pip-tools, Poetry, uv or conda-lock produce lock files that also pin sub-dependencies. conda or mamba environments are popular when you need non-Python libraries (CUDA, GDAL) or several Python versions.

Use a project-specific Jupyter kernel (python -m ipykernel install --user --name myproject) so notebooks run in the right environment, record the Python version, and avoid pip install inside notebook cells without recording it. A short README with the setup commands is part of the project, not an extra.

Setting up a project from scratch

python -m venv .venv, source .venv/bin/activate, pip install pandas scikit-learn jupyter, pip freeze > requirements.txt, then git init and add .venv/ to .gitignore.

Key takeaway: One environment per project, with versions recorded and the setup written down.

A Git workflow for analysis work

The core loop is git status, git add <files>, git commit -m "Fix timezone bug in order dates", git push. Commit small, coherent changes with messages that say why. Use a branch per task (git switch -c feature/churn-features), open a pull request for review, then merge. git log --oneline shows history, git diff shows changes, and git restore <file> or git revert <commit> undoes mistakes safely.

Notebooks diff badly because they contain outputs; clear outputs before committing, or use tools like nbstripout, jupytext (pairing notebooks with plain .py) or review notebooks in a viewer that understands them. Keep large data and model files out of Git (use DVC, Git LFS or object storage), keep secrets in environment variables or a secrets manager rather than in code, and tag releases that produced published results (git tag report-2026-q4). If a secret is committed, rotate it: deleting the file doesn't remove it from history.

Experiments on a branch

git switch -c try-xgboost, commit the experiment, and compare metrics. If it wins, merge; if not, delete the branch. The main branch always stays runnable.

Key takeaway: Small commits, a branch per idea, outputs and secrets kept out of history.

How it works, step by step

Step 1 of 4
Terminal

1. Create the environment

Make a project folder, create and activate a virtual environment, and install only what you need.

python -m venv .venv · pip install pandas
Key numbers at this step
Per project
one env

When to use it & trade-offs

What it is

A virtual environment (python -m venv .venv, or a conda environment) is an isolated folder of Python packages for one project, so project A can use pandas 1.5 while project B uses pandas 2.2. Git records every change to your code as a commit, so you can compare versions, undo mistakes, work on branches and share through a remote such as GitHub. Together they answer "it worked yesterday" and "it works on my machine".

Why it matters: Data work breaks silently when package versions drift: a model trained with one scikit-learn version may load differently in another, and a notebook that ran last month stops running. Reproducible environments and version control are the minimum expectation for team projects, and interviews often ask how you'd make a result reproducible.

When to reach for it

  • A separate environment for every project
  • Pinned requirements for anything you report or deploy
  • Branches and pull requests for team analysis work

When to avoid or be careful

  • Installing everything into the global Python
  • Committing data files, keys or .venv
  • Committing notebooks with huge outputs

Environment tools

venv + pip
Best for: Simple Python projects

Strengths: Built in; lightweight.

Watch out: Doesn't manage non-Python libraries or Python versions.

conda / mamba
Best for: Scientific stacks with compiled or CUDA dependencies

Strengths: Manages Python and system libraries.

Watch out: Heavier; environments can be slow to solve.

Poetry / uv with lock files
Best for: Reproducible team projects and packages

Strengths: Exact, resolved lock files; fast installs (uv).

Watch out: Another tool to learn.

Interview signals & numbers to know

When this topic comes up

  • “It works on my machine”
  • “How do you make results reproducible?”
  • “We leaked an API key in the repo”
  • Dependency pinning
  • Notebook version control

Benchmarks & rules of thumb

1 -
environment per project
0 -
secrets allowed in a repository
small -
preferred commit size

Common mistakes & follow-ups

Common interview mistakes

  • Using the global Python for everything and then breaking two projects with one upgrade.
  • Committing a .env file with an API key, then simply deleting it in the next commit.
  • Storing a 2 GB CSV in Git, making every clone slow.

Likely interviewer follow-ups

  • How would you make a data science project reproducible?
  • What goes in .gitignore for a data project?
  • How do you review changes to notebooks?
Interview tip: Describe reproducibility as three things: pinned environment, versioned code (with a tag for reported results), and a fixed random seed. That's a complete answer.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Virtual Environments & Git Version Control with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Functions, Modules & OOP Basics
Next topic
NumPy Arrays & Vectorization