What is uv?

  • uv is an extremely fast Python package and project manager, written in Rust by Astral. 1
  • It replaces several separate tools you’d otherwise need — pip, venv, pip-tools, and poetry — with a single command, uv.
  • For the corresponding exercise, we’ll use uv to manage the Python environment and packages (like pandas, openpyxl, and xlrd) behind our Jupyter Notebook in VS Code, instead of downloading a pre-built .ipynb file.

Why Use uv for Jupyter Notebooks?

  • Speed: uv is commonly 10-100x faster than pip at resolving and installing packages.
  • One tool instead of many: no more juggling pip, venv, and separate installers.
  • Reproducible environments: uv creates a lockfile so that every notebook you build uses the exact same package versions.
  • Works directly with VS Code’s Jupyter extension: Integrates with VS Code’s Jupyter extension — the .venv folder that uv creates is (usually) automatically detected as a selectable kernel for your .ipynb files, right within VS Code.
    • If the kernel doesn’t appear, press Ctrl+Shift+P / Cmd+Shift+P, select Python: Select Interpreter, and choose the .venv folder that uv created in your project folder.

How Can I Install uv? (Mac)

  • Open the VS Code Terminal and run:
1curl -LsSf https://astral.sh/uv/install.sh | sh
  • Alternatively, first install Homebrew (MacOS Only).
    • Homebrew is a package manager for MacOS that allows you to easily install software and manage packages.
    • Install Homebrew by visiting the Homebrew website and following the installation instructions.
      • After Homebrew is installed, run the following command in the VS Code Terminal to install uv:
1brew install uv

How Can I Install uv? (Windows)

  • In the VS Code terminal, run:
bash
1pip install uv
  • Reference: pypi.org

  • Alternatively you can use the standalone installer. Open PowerShell and run:

powershell
1powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

How Can I Test That uv Is Installed?

  • Close and reopen all terminals (so it picks up the new install), then run:
bash
1uv --version
  • If installed correctly, you’ll see output similar to:
bash
1uv 0.12.5

How Do I Set Up a uv Project for a Jupyter Notebook?

  1. Create (or open) the folder in VS Code where this exercise’s notebook will live.
  2. In the VS Code terminal, initialize a uv project (only needs to be done once per folder):
bash
1uv init --no-package
  • This creates a pyproject.toml file and a .venv folder that uv will manage for you.
  1. Add jupyter so this environment can be used as a Jupyter kernel:
bash
1uv add jupyter
  1. Also add the following packages you’ll need for this exercise (pandas, plus the Excel engines covered below):
bash
1uv add pandas openpyxl xlrd

How Do I Create and Run My Notebook in VS Code?

  1. In VS Code, create a new file in your project folder and name it with an .ipynb extension, then save it into your project folder.
  2. Open the notebook and click Select Kernel in the top-right corner.
  3. Choose Python Environments, then select the .venv that uv created in your project folder (it will usually be listed with the folder name and a (.venv) tag).
  4. Write your code in a cell and run it with Shift+Enter, or use the Run All button at the top of the notebook to run every cell in order.
  • Note: If the kernel doesn’t appear, press Ctrl+Shift+P / Cmd+Shift+P, select Python: Select Interpreter, and choose the .venv folder that uv created in your project folder.

How Do I Add or Remove Packages with uv?

  • To add a package(s) with uv, use uv add. This installs the package into your .venv and updates pyproject.toml and the lockfile:
bash
1uv add openpyxl xlrd
  • To remove a package, use uv remove. This uninstalls it from .venv and updates pyproject.toml and the lockfile:
bash
1uv remove xlrd
  • After running uv add or uv remove while your notebook’s kernel is already running, restart the kernel so the running Python process picks up the change, then re-run your cells.

  • Reference: Managing Dependencies with uv


Why Do I Need openpyxl and xlrd?

  • pandas doesn’t read Excel files entirely on its own — the read_excel() function hands the work off to a separate engine package depending on the file format:
    • openpyxl is the engine pandas uses for modern Excel files (.xlsx, .xlsm).
    • xlrd is the engine pandas uses for the older, legacy Excel format (.xls).
  • If the matching engine isn’t installed in your environment, pd.read_excel() will raise an ImportError telling you which package it’s missing.

Footnotes

  1. uv Python package manager, by Astral. ↩