Setting up Python and VS Code for the labs
At the end of this guide you will have:
- VS Code, the editor in which you open and run the lab notebooks;
- Python 3.13 in an environment that belongs to the course folder, with the packages of the labs (numpy, matplotlib, pandas, scikit-learn);
- Lab 0 (scientific computing in Python) open and running.
Count about 20 minutes and 1 GB of disk space, with an internet connection. Steps 1 and 2 depend on your system (pick your tab); steps 3 to 6 are the same everywhere.
Why an environment? An environment is a folder (.venv) that holds one Python and the packages you install into it, separate from anything else on your computer. If it breaks, you delete the folder and run two commands again; nothing else is affected.
Why Python 3.13 and not the newest version? The later labs use packages (UMAP, PyTorch) that reach a new Python version a few months after its release. Python 3.13 runs all of them.
Step 1. Install VS Code
Download it from https://code.visualstudio.com/download.
- Download the User Installer for Windows (x64; ARM64 only if your laptop has an ARM processor, such as a Snapdragon).
- Run it. Keep the box Add to PATH ticked (it is by default). Ticking Add “Open with Code” action is handy but optional.
- Download the Mac Universal
.zip. - Open it, then drag Visual Studio Code.app into the Applications folder. Do not run it from Downloads: updates fail there.
On Ubuntu or Debian, download the .deb and install it from a terminal opened in the download folder:
sudo apt install ./code_*.debOn Fedora, download the .rpm and run sudo dnf install ./code-*.rpm. Elsewhere, sudo snap install code --classic works on most distributions.
Step 2. Install uv
uv is a small program that installs Python itself and the packages of the labs. With it, the commands of steps 3 and 4 are the same on Windows, macOS and Linux.
Open PowerShell (Start menu, type PowerShell) and run:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Open Terminal (Cmd + Space, type Terminal) and run:
curl -LsSf https://astral.sh/uv/install.sh | shOpen a terminal and run:
curl -LsSf https://astral.sh/uv/install.sh | shIf curl is missing, use wget -qO- https://astral.sh/uv/install.sh | sh instead.
Then close the terminal and open a new one, and check that uv answers:
uv --versionIf you get command not found (or not recognized on Windows), restart your computer and try again.
Step 3. Create the course folder and its environment
- Create a folder named
DRin your home folder.- On Windows, put it at
C:\Users\<your name>\DR, not inside OneDrive (OneDrive tries to sync the thousands of files of the environment and slows everything down). - Avoid accents in the folder path.
- On Windows, put it at
- In VS Code: File > Open Folder… and choose
DR. If VS Code asks whether you trust the authors of the files, answer yes. - Open the terminal inside VS Code: Terminal > New Terminal. Its prompt ends with the path of your
DRfolder. - Create the environment:
uv venv --python 3.13uv downloads Python 3.13 if your computer does not have it, and creates the folder .venv inside DR.
Step 4. Install the packages
In the same terminal, still in the DR folder:
uv pip install numpy matplotlib pandas scikit-learn ipykernelipykernel is what lets VS Code run notebook cells with this Python.
Later labs need one or two more packages; each lab says which, and you install them the same way (for example uv pip install umap-learn), always from the DR folder.
Step 5. Set up VS Code
- Extensions. Click the Extensions icon in the left bar (four squares) and install Python and Jupyter, both published by Microsoft.
- Turn off the AI suggestions. Recent VS Code versions suggest code as you type and come with a chat assistant. The labs ask you to type the code yourself, so turn these off: File > Preferences > Settings (on macOS: Code > Settings > Settings), search for
disable AI features, and tick Chat: Disable AI Features.
Step 6. Open and run Lab 0
- Download lab0_scientific_computing.ipynb and move the file
lab0_scientific_computing.ipynbinto yourDRfolder. It appears in the file list on the left of VS Code. - Open
lab0_scientific_computing.ipynb. - Click Select Kernel at the top right of the notebook, then Python Environments, then the one marked
.venv(Python 3.13). - Click in the first code cell and press Shift + Enter to run it and move to the next cell. The first run takes a few seconds.
To check that everything is in place, add a code cell (button + Code) at the top of the lab and run:
import sys, numpy
print(sys.executable)
print(numpy.__version__)The first line printed must contain .venv. If it does, delete this cell and start the lab. For each new lab, choose the .venv kernel the same way.
When something goes wrong
.venv is not in the kernel list. Open the command palette (Ctrl + Shift + P, or Cmd + Shift + P on macOS), run Python: Select Interpreter, choose Enter interpreter path… and give .venv\Scripts\python.exe on Windows, .venv/bin/python on macOS and Linux. Then choose the kernel again. Make sure you opened the DR folder in VS Code (step 3.2), not only the notebook file.
VS Code says Running cells requires the ipykernel package. Click Install, or rerun the command of step 4.
ModuleNotFoundError: No module named 'numpy'. The notebook runs on another Python than .venv: choose the kernel again (step 6.3).
uv: command not found in the VS Code terminal only. VS Code was open while uv was installed: close VS Code completely and reopen it.
The environment is broken, or you are lost. Delete the .venv folder and redo steps 3.4 and 4. Your notebooks are not touched.
Plan B, without uv. If uv cannot be installed on your computer, install Python 3.13 from https://www.python.org/downloads/ (on Windows, with the Python install manager from that page, then py install 3.13 in PowerShell; on Ubuntu or Debian, sudo apt install python3-venv as well). Then, in the DR folder, replace steps 3.4 and 4 by:
python3 -m venv .venv # Windows: py -V:3.13 -m venv .venv
.venv/bin/python -m pip install numpy matplotlib pandas scikit-learn ipykernel
# Windows: .venv\Scripts\python -m pip install numpy matplotlib pandas scikit-learn ipykernel