Setting up: Python, VS Code and Jupyter
Why install anything?
In these pages, Python runs inside your browser, so you can start straight away. Real work happens on your own computer, because there:
- your files stay, in folders you choose;
- you can open big data files, many megabytes long;
- you can install any of the thousands of free Python tools.
You need three things: Python itself, VS Code (an editor to write code in), and Jupyter (notebooks, where code and results sit together). All three are free.
Keep using these pages to learn. Install the tools today so they're ready when your projects start.
First, Python.
Installing Python
- Go to python.org, open Downloads, and download the latest Python 3 for your computer.
- Windows: run the installer and tick "Add python.exe to PATH" on its first screen, then press Install Now.
Mac: open the downloaded file and follow the steps. - Check it worked: open a terminal (Windows: search "Command Prompt"; Mac: search "Terminal") and type
python --version. On a Mac, typepython3 --version.
If it prints a version, like Python 3.14.0, Python is ready.
The PATH box wasn't ticked, so the terminal can't find Python. Run the installer again, choose Modify, and tick "Add Python to environment variables".
python --version and press Enter.Python is installed. Now we need somewhere comfortable to write code.
VS Code: an editor for code
You could write Python in Notepad, but an editor made for code colours it, spots mistakes and runs it for you. We use VS Code.
- Download it from code.visualstudio.com and install it.
- Open it, click the Extensions icon (four squares) on the left, search Python, and install the one by Microsoft.
- Make a folder for your work, like
data-course, and open it: File → Open Folder. - New file:
hello.py. Typeprint("Hello!"), save, and press the ▶ button at the top right.
The answer appears in the terminal panel at the bottom: VS Code ran python hello.py for you.
Let's do exactly that by hand.
Running a Python file
A file that ends in .py holds Python code. The command python hello.py tells Python: "run every line of this file, from the top".
Below, echo … > hello.py writes a line into a new file (you'll learn this in the next lesson), and cat hello.py shows what's in it.
echo 'print("Hello from a file!")' > hello.pycat hello.pypython hello.pyPress ↑ in the terminal to bring back the last command, instead of typing it again.
Python comes with the basics. Data tools like pandas must be added.
Packages and pip
A package is a set of ready-made Python tools that someone wrote and shared. pandas (for tables) and Matplotlib (for charts) are packages.
pip is the program that downloads and installs packages: pip install pandas. pip list shows what's installed.
No. These pages already have pandas, Matplotlib and the rest. You install them only on your own computer.
pip install pandas, then pip list. Read the note pip prints at the end.That note warns about a problem. Here's how to avoid it.
Virtual environments
If every project installs into the same Python, two projects that need different versions of a package will clash. So each project gets its own private set of packages, called a virtual environment.
python -m venv .venvmakes one, in a folder called.venv.source .venv/bin/activateswitches it on (on Windows:.venv\Scripts\activate). The prompt starts with (.venv).- Now
pip installputs packages in this project only.deactivateswitches it off.
Files are great for programs. For exploring data, there's something better.
Jupyter notebooks
A notebook is a file (ending in .ipynb) made of cells. Each cell holds a little code; you run one cell at a time, and its result appears right under it. Earlier cells' variables stay, so the next cell can use them.
That's ideal for data: load the data in one cell, look at it, then try the next step in the next cell. In VS Code: install the Jupyter extension, make a file explore.ipynb, and press Shift + Enter to run a cell.
prices from the first.Run the second box first and you get an error: prices doesn't exist yet. Notebooks have the same rule: run the cells in order.
Time to set up a project in the terminal on your own.
Practice 1.1: a new project
mkdir name makes a folder, cd name goes into it, python -m venv .venv makes an environment.Set up a project folder the way you would on your own computer. The list ticks itself as you go.
Ready? A short test on this lesson.
Lesson 1 test
Think first, then pick. A wrong answer shows which page to read again.
report.py from the terminal?seaborn on your computer. What do you type?prices; cell 2 prints max(prices). You open the notebook and run only cell 2. What happens?