PEP 723 Script Metadata
marimo notebooks can include dependency information at the top of the file:notebook.py
The
# /// markers define a PEP 723 metadata block. This is a standard format supported by tools like uv.Auto-Install with uv
When using--sandbox mode, marimo automatically manages dependencies using uv.
Installing uv
First, installuv:
Running in Sandbox Mode
Single Notebook
Single Notebook
- marimo detects the PEP 723 metadata
- Prompts: “Run in a sandboxed venv?”
- Creates an isolated environment with
uv - Installs all dependencies automatically
- Runs the notebook in that environment
Multiple Notebooks (Directory)
Multiple Notebooks (Directory)
- Each notebook has its own isolated venv
- Dependencies are per-notebook, not shared
- Requires
pyzmqfor IPC communication:
Managing Dependencies
Adding Packages
marimo provides a UI for adding packages, or you can useuv directly:
Version Constraints
Specify version requirements using standard pip syntax:Python Version
Specify required Python version:Package Sources
Custom Index URLs
Use private PyPI servers or mirrors:Extra Index URLs
Combine multiple package sources:Named Indexes
Use named indexes for better control:Auto-Install on Import
When running without--sandbox, marimo can detect missing packages:
Serializing Dependencies
Export Requirements
Generate arequirements.txt from script metadata:
requirements.txt
Lock Files
For reproducible environments, use lock files:Virtual Environments
Manual Virtual Environments
You can still use traditional virtual environments:Sandbox vs. Manual venvs
| Feature | Sandbox (--sandbox) | Manual venv |
|---|---|---|
| Setup | Automatic | Manual |
| Isolation | Per-notebook | Per-project |
| Persistence | Ephemeral (cached) | Persistent |
| Dependencies | From PEP 723 metadata | requirements.txt |
| Switching | Automatic | Manual activation |
| Best for | Notebooks, scripts | Projects, apps |
Environment Variables
Metadata Management
Control when marimo manages metadata:- Adds
marimoto dependencies if missing - Updates
requires-pythonbased on current Python version - Keeps metadata in sync with your environment
Common Workflows
Starting a New Notebook
Starting a New Notebook
Sharing a Notebook
Sharing a Notebook
Updating Dependencies
Updating Dependencies
Running in Production
Running in Production
Troubleshooting
uv not found
uv not found
Problem:
marimo edit --sandbox fails with “uv not found”Solution: Install uv:pyzmq missing (multi-file sandbox)
pyzmq missing (multi-file sandbox)
Problem:
marimo edit ./dir --sandbox failsSolution: Install sandbox extras:Package installation fails
Package installation fails
Problem: Dependency resolution errorsSolution:
Slow first install
Slow first install
Problem: First
--sandbox run is slowSolution: This is normal - uv is creating a venv and installing packages. Subsequent runs use cached environments.Speed it up:Best Practices
Comparison with Other Tools
| Tool | marimo + uv | pip + requirements.txt | conda |
|---|---|---|---|
| Metadata location | In notebook file | Separate file | environment.yml |
| Isolation | Per-notebook | Per-environment | Per-environment |
| Speed | Very fast (uv) | Moderate | Slow |
| Standard | PEP 723 | requirements.txt | conda format |
| Version control | Single file | Multiple files | Multiple files |
Advanced Configuration
Editable Installs
For development, install packages in editable mode:Environment-Specific Dependencies
Use environment markers:Next Steps
Creating Notebooks
Learn notebook structure and cells
Running Notebooks
Explore execution modes