Set up Python
About 20 minutes, before the first Python session.
Do this before the first Python session, at home, on
the laptop you will bring. It takes about 20 minutes, most of it waiting
for downloads. When the last step prints
All good: you are ready for the course. you are done.
You install three things: uv (it fetches Python and the course packages for you), VS Code (where you write and run code) and the course folder. You do not need to install Python yourself, and you do not need Anaconda.
Step 1. Install uv (2 minutes)
Mac: open Terminal (press Cmd+Space, type Terminal) and paste:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows: open PowerShell (press the Windows key, type PowerShell) and paste:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Then close the window and open a new one, and type
uv --version. You should see a version number.
Step 2. Install VS Code (5 minutes)
Download VS Code from code.visualstudio.com and install it. Open it, click the Extensions icon on the left (four squares) and install two extensions, both by Microsoft: Python and Jupyter. Jupyter gives you the Run Cell buttons we use in class.
Step 3. Get the course folder (1 minute)
Download na446a-starter.zip, unzip it, and
move the folder na446a-starter to your home
folder, the one with your user name. On a Mac: in Finder press
Cmd+Shift+H. On Windows: open File Explorer and type
%USERPROFILE% in the address bar.
Why there: Documents and Desktop are often synced to iCloud or OneDrive, and syncing thousands of small files while Python runs causes strange errors. The course environment is large (about half a gigabyte), so keep it out of the cloud.
Step 4. Install Python and the course packages (5–10 minutes)
In VS Code: File → Open Folder… and choose
na446a-starter. Then Terminal → New Terminal and
type:
uv sync
uv downloads the right Python and the course packages into a hidden
folder .venv inside the course folder. Nothing else on your
computer changes.
Step 5. Check that everything works (1 minute)
Open scripts/check_setup.py and press the play button
(▷) at the top right. If VS Code asks which Python to use, choose the
one that mentions .venv. Every line should say OK:
Python 3.12 or newer OK
Course packages installed OK
Read a CSV from data/raw OK
Save a figure to output/ OK
Run SQL with DuckDB OK
Running inside the project's .venv OK
All good: you are ready for the course.
If something fails
uvis not found: you did not open a new terminal after Step 1. Close it, open a new one.- The last check says “not the course environment”:
press Ctrl+Shift+P (Cmd+Shift+P on a Mac), type Python: Select
Interpreter and choose the one with
.venv. - Anything else: email magnus.lodefalk@oru.se with the
subject NA446A setup, and paste three things: what you did,
what you expected, and all the output from
check_setup.py. A screenshot of the error helps too. - Your laptop will not cooperate (work laptop without admin rights, very old machine): come to the setup drop-in, and see Plan B below.
Setup drop-in: one online drop-in before the first Python session; the date and link will be posted here.
Plan B: if your laptop is not ready in time
Come to Session 1 anyway and work with a classmate on their laptop for the lab; the slides show every result, so you lose nothing. Email me before or after the session and we fix your setup before Session 2.
What you just installed, in one paragraph
uv manages Python versions and packages, like
Stata’s ssc install but for the whole project at once.
.venv is the course’s own Python with its
own packages, so the course cannot break other Python on your computer,
and other projects cannot break the course. VS Code is
the editor; the terminal inside it is where you type commands.
You will use the same three pieces in your thesis.