Python
Topic 21 · Tools of the trade · ⏱ about 8 h

Your Developer Toolkit

The terminal, git and GitHub, virtual environments, Jupyter and VS Code, project structure and tests: what every intern uses on day one.

Show:
In this topic
Beginner

Why the tools matter

In this course everything runs in the browser. At work, day one looks different: you get access to a repository on GitHub or GitLab, clone it to your laptop with git, create a virtual environment, install the dependencies, run the tests, make a small change on a branch and open a pull request for review. None of that is machine learning, and all of it is expected of an intern.

The good news: you need a small core of each tool, and it is the same everywhere. This topic gives you that core and a safe place to practise git.

Beginner

The terminal

The terminal (also called the shell or command line) is a text interface to your computer. On macOS and Linux open Terminal; on Windows install Git Bash or use WSL so the commands match. You type a command, press Enter, and it prints a result. You are always in a folder, the working directory.

pwd # print working directory: where am I? ls # list files here (ls -la shows hidden files and details) cd projects # change directory into projects cd .. # go up one level mkdir noshow # make a directory python train.py # run a Python script cat README.md # print a file ↑ (up arrow) # previous command; Tab completes names

Paths can be absolute (/Users/alisha/projects) or relative to where you are (data/raw.csv). Most "file not found" errors are a script run from a different folder than you think: check with pwd.

Beginner

Environments, packages and editors

Each project should have its own virtual environment: a private folder of packages, so one project's versions never break another's.

python -m venv .venv # create it (once per project) source .venv/bin/activate # activate it (Windows: .venv\Scripts\activate) pip install pandas scikit-learn # install packages into it pip freeze > requirements.txt # record exact versions pip install -r requirements.txt # recreate the environment elsewhere

Conda (or the faster uv) are popular alternatives; the idea is the same. Editors: Jupyter notebooks (or Google Colab) are best for exploring data and showing results step by step; VS Code is best for code that will be reused, tested and deployed. A common path is to explore in a notebook, then move the working code into .py files with functions and tests.

A typical ML project layout:

noshow/ β”œβ”€β”€ README.md what it does, results, how to run it β”œβ”€β”€ requirements.txt β”œβ”€β”€ .gitignore data/, .venv/, *.pkl, .env β”œβ”€β”€ data/ not committed: too big and often private β”œβ”€β”€ notebooks/01_explore.ipynb β”œβ”€β”€ src/noshow/features.py, train.py, predict.py └── tests/test_features.py
Beginner

git and GitHub

git records the history of your project as a series of commits (snapshots with a message). You choose what goes into the next commit by staging files. Branches let you work on a change without disturbing the main version. GitHub hosts a copy of the repository (the remote) so a team can share it, review changes and run automated checks.

git clone https://github.com/team/noshow.git # copy a remote repo git switch -c fix-lead-days # create a branch and switch to it # ... edit files ... git status # what changed? git diff # the exact lines that changed git add src/noshow/features.py # stage a file git commit -m "Clip negative lead_days to 0" git push -u origin fix-lead-days # upload the branch # on GitHub: open a Pull Request β†’ review β†’ merge into main git switch main && git pull # update your copy afterwards

Good habits: small commits with clear messages; never commit secrets (passwords, API keys) or patient data, and list such files in .gitignore; pull before starting work; read the diff before committing. If a merge conflict happens, git marks both versions in the file; you edit it to the correct result, then add and commit.

Try it

Try it: a safe git practice terminal

A simulated terminal: nothing here touches a real computer. Work through the missions on the right; type help to see the commands it understands.

Interactive: this part runs in your browser.

Beginner

Tests and code quality

A test is code that checks other code. With pytest, any function named test_... in a file named test_....py is a test, and assert states what must be true. Run all tests with pytest in the terminal.

# tests/test_features.py from noshow.features import clip_lead_days def test_negative_lead_days_become_zero(): assert clip_lead_days(-3) == 0 def test_normal_values_unchanged(): assert clip_lead_days(14) == 14

In ML code, the most valuable tests check data and feature logic: no future information in features, expected columns and ranges, no duplicated rows after joins, and that the training pipeline runs end to end on a tiny sample. Teams also run a formatter and linter (such as black and ruff) automatically, and CI (continuous integration, e.g. GitHub Actions) runs the tests on every pull request.

Try it

Code example: write tests that catch bugs

A worked example: read it step by step (every part is explained), then run it and experiment.

Interactive: this part runs in your browser.

Advanced

Using AI assistants and documentation well

AI coding assistants are now part of most engineers' workflow, and employers expect you to use them, responsibly. They are excellent for explaining an error, suggesting how to use an unfamiliar library, and drafting boilerplate. They are risky when you paste code you don't understand: it may be subtly wrong, use an outdated API, or leak data. A good rule: you own every line you commit. Read it, run it, test it.

Never paste confidential data (patient records, company secrets, API keys) into external tools unless your organisation has approved them for that data. And learn to read official documentation: every topic in this course ends with links to it. Being able to answer your own question from the docs is one of the skills that most distinguishes a strong junior.

Try it

Cheat sheet: Terminal & git

The commands you will use most, on one screen. Come back to it while you work.

Interactive: this part runs in your browser.

Check yourself

Quiz

1. You run python train.py and get "No such file or directory: data/raw.csv", but the file exists. The most likely cause is…

2. What is the correct order to save a change in git?

3. Which files should go in .gitignore?

4. What does pip install -r requirements.txt do?

5. Where do you propose your change for review on GitHub?

Go deeper

πŸ“š Further reading

Trusted, mostly free sources: official documentation, well-known textbooks and courses. When you want to confirm or go deeper on anything here, start with these.

Ready