Setting up your environment
Install Python, create a project with its own packages, choose between Jupyter and VS Code, and confirm everything works with a short check script.
In this lesson you will
- Install a current version of Python and a package manager.
- Create a project folder with its own isolated set of packages.
- Run Python code from a notebook and from a script file.
- Confirm your setup with a version-check script and read its output.
Before any trading idea can be tested, you need a place to write and run code. This lesson sets one up. It takes perhaps fifteen minutes, and you only do it once. If you already use Python, skim the commands and run the check script at the end to confirm your versions.
The setup has three parts: Python itself, a way to install packages into a project, and an editor to write code in.
Why a project environment matters
Python on its own does a lot, but the tools this course uses come as separate packages: numpy for arrays of numbers, pandas for tables of data, and matplotlib for charts. Packages are updated regularly, and new versions sometimes change behaviour. A backtest that ran one way last year might print slightly different numbers after an update.
The answer is a project environment: a folder-specific set of packages, with their versions recorded. Each project gets its own, so updating one never breaks another, and you can always recreate exactly the setup that produced a result. For work whose whole point is reproducible evidence, this matters.
Option A: uv (recommended)
uv is a free tool that installs Python, creates project environments and manages packages. It is fast and handles all three jobs with a few commands. Install it from a terminal (Terminal on macOS, PowerShell on Windows):
curl -LsSf https://astral.sh/uv/install.sh | shpowershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Close and reopen the terminal so it can find the new command, then create the course project:
uv python install 3.12
mkdir scuta-quant
cd scuta-quant
uv init --python 3.12
uv add numpy pandas matplotlib jupyterlabLine by line: install Python 3.12; make a folder and move into it; turn the folder into a project that uses Python 3.12; add the four packages. uv init creates a pyproject.toml file describing the project, and uv add records each package there and in a uv.lock file that pins the exact versions.
To run Python inside the project, put uv run in front of the command: uv run python check_setup.py runs a script, and uv run jupyter lab opens a notebook.
Option B: venv and pip
If you would rather use the tools that come with Python, install Python 3.12 from python.org, then create an environment with the built-in venv module and install packages with pip:
mkdir scuta-quant
cd scuta-quant
python3 -m venv .venv
source .venv/bin/activate
pip install numpy pandas matplotlib jupyterlabOn Windows, use python instead of python3, and activate with .venv\Scripts\activate. The environment is active for that terminal window only; you will see (.venv) at the start of the prompt. Run deactivate to leave it, and activate it again each time you open a new terminal. In this option, python check_setup.py runs a script and jupyter lab opens a notebook, without uv run in front.
Choosing an editor
You need somewhere to write and run code. Two good free options:
JupyterLab runs in your browser. Code lives in cells; you run a cell and its output appears directly below it, charts included. This is ideal for exploring data step by step. Start it from the project folder with uv run jupyter lab (or jupyter lab in an active venv), then create a new notebook.
VS Code is a general code editor. Install the Python and Jupyter extensions from its extensions panel, open the project folder, and select the project's environment as the interpreter when prompted. You can then run .py script files and open notebooks in the same window.
Many people use both: a notebook to explore, and script files for anything that has to run exactly the same way twice. Notebooks let you run cells in any order, which is convenient but makes it easy to end up with results that depend on a cell you ran an hour ago and later deleted. When a result matters, put the code in a script and run it from top to bottom.
Your first program
Create a file called first.py in the project folder with these lines, then run it:
account = 25_000
risk_per_trade = 0.01
print("Risk per trade in dollars:", account * risk_per_trade)Risk per trade in dollars: 250.0Three things happened. The first line stored the number 25,000 under the name account; Python lets you write underscores in long numbers to make them readable. The second stored 1% as the decimal 0.01. The third multiplied them and printed the result. The next lesson explains each of these ideas properly.
Check your setup
This script imports each package and prints its version. Save it as check_setup.py and run it.
import sys
import matplotlib
import numpy as np
import pandas as pd
print(f"Python {sys.version.split()[0]}")
print(f"numpy {np.__version__}")
print(f"pandas {pd.__version__}")
print(f"matplotlib {matplotlib.__version__}")Python 3.12.15
numpy 2.5.3
pandas 3.0.6
matplotlib 3.11.2import loads a package so your code can use it. import numpy as np loads numpy under the shorter name np, a convention almost every Python user follows; the same goes for pd for pandas. The f before each string makes it an f-string, which replaces anything inside curly braces with its value.
These are the versions used to produce every output in this module. Newer versions should work, though printed numbers can occasionally differ in the last decimal place. If any import fails, the environment is missing that package; add it with uv add or pip install and run the script again.
How to use the code in this course
Every code block is a complete program. You can paste it into a new file and run it, or paste it into a notebook cell. Where a block shows printed output underneath, that output came from running exactly that code with the versions above. If yours differs, compare carefully: the difference usually points to a typo, a changed line, or a different package version.
All data in the course is synthetic, generated by code with a fixed random seed. Nothing requires an internet connection after installation, an account with any data provider, or real money.
Key takeaways
- Each project should have its own environment, so that package versions are recorded and results can be reproduced.
- uv is a fast way to install Python and manage packages; the built-in venv and pip work too.
- Notebooks are good for exploring; script files are good for anything you want to rerun exactly.
- Every code example in this course is a complete program that you can paste into a file or a notebook cell and run.
Build and verify your course project
Create a folder called scuta-quant with its own environment containing numpy, pandas, matplotlib and JupyterLab. Run check_setup.py from this lesson as a script, then run the same code in a notebook cell. Save the printed versions in a text file in the project, so that you can compare them later if a result ever changes.
Self-check
Answer in your own words first, then reveal the answer.
Why give each project its own environment instead of installing packages once for the whole computer?
Show answerHide answer
Packages change between versions, sometimes in ways that alter results. A project environment records exactly which versions a project uses, keeps projects from breaking each other, and lets you or anyone else reproduce the same output later.
When would you choose a script file over a notebook?
Show answerHide answer
When you want to rerun the same steps exactly, from top to bottom, for example a backtest or a report. Notebooks are convenient for exploring, but cells can be run out of order, which makes it easy to get results that depend on hidden state.
What does
uv add pandasdo inside a project?Show answerHide answer
It installs pandas into the project's own environment and records it, with its version, in the project's
pyproject.tomlanduv.lockfiles, so that the same setup can be recreated later.
