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- Reference: uv Installation Guide
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"- Reference: uv Installation Guide
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.5How Do I Set Up a uv Project for a Jupyter Notebook?
- Create (or open) the folder in VS Code where this exerciseâs notebook will live.
- 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.
- Add jupyter so this environment can be used as a Jupyter kernel:
bash
1uv add jupyter- Also add the following packages youâll need for this exercise (pandas, plus the Excel engines covered below):
bash
1uv add pandas openpyxl xlrdHow Do I Create and Run My Notebook in VS Code?
- 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.
- Open the notebook and click Select Kernel in the top-right corner.
- 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).
- 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
-
uv Python package manager, by Astral. â©