How to Run a Python REPL with uv

January 23, 2025
ℹ️
This is an excerpt from the forthcoming Python Developer’s Tool Handbook. The handbook provides comprehensive guidance on Python tooling and best practices for modern Python development.

To start an interactive Python REPL (Read-Eval-Print Loop) session using uv:

$ uv run python

This command will:

  1. Create or use an existing virtual environment if in a project (i.e. the project has a pyproject.toml file)
  2. Install any required dependencies
  3. Launch an interactive Python session

Using a Specific Python Version

To run the REPL with a particular Python version:

$ uv run --python 3.12 python

If the requested Python version is not installed, uv will download and install it automatically.

Running the REPL with Additional Dependencies

To run Python with specific packages available:

$ uv run --with pandas --with numpy python

This will create an isolated environment with the requested packages installed before launching the REPL.

Running the REPL Isolated from a Project

When working in a project directory but wanting to run a clean REPL without project dependencies:

$ uv run --no-project python
ℹ️
If you need regular access to a Python REPL, you could install IPython on the system level with uv tool install ipython. uv does not currently support a system-level installation of Python.
Last updated on

Please submit corrections and feedback...