Skip to content

How to migrate from Pipenv to uv

Pipenv combines pip and virtualenv into a single tool. uv covers the same ground and adds Python version management, a standards-compliant pyproject.toml-based workflow, and 10-100x faster dependency resolution.

Migrating replaces the Pipfile and Pipfile.lock with pyproject.toml and uv.lock, and swaps pipenv commands for their uv equivalents.

Automated migration

The migrate-to-uv tool automates the conversion.

1. Run the migration tool

$ uvx migrate-to-uv

The tool reads your Pipfile and:

  • Creates a pyproject.toml with [project] metadata and [dependency-groups]
  • Translates [packages] to dependencies and [dev-packages] to the dev dependency group
  • Generates a uv.lock file from the resolved dependencies in Pipfile.lock
  • Removes Pipfile and Pipfile.lock

2. Verify the result

$ uv sync
$ uv run pytest

Manual migration

If the automated tool doesn’t cover your setup, map Pipfile sections to pyproject.toml by hand.

A typical Pipfile:

Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = ">=2.28"
click = ">=8.0"

[dev-packages]
pytest = ">=7.0"
ruff = "*"

[requires]
python_version = "3.11"

Becomes:

pyproject.toml
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
    "requests>=2.28",
    "click>=8.0",
]

[dependency-groups]
dev = [
    "pytest>=7.0",
    "ruff",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

Key translations:

Pipfile pyproject.toml
[packages] [project] dependencies
[dev-packages] [dependency-groups] dev
[requires] python_version [project] requires-python
[source] (non-default index) [[tool.uv.index]]
"*" (any version) omit the version constraint

After creating pyproject.toml, generate the lockfileA file that records the exact version of every installed package, so everyone working on the project gets identical installs. :

$ uv lock
$ uv sync

Then delete Pipfile and Pipfile.lock.

Command equivalents

Pipenv uv
pipenv install uv sync
pipenv install requests uv add requests
pipenv install --dev pytest uv add --dev pytest
pipenv uninstall requests uv remove requests
pipenv run python script.py uv run python script.py
pipenv run pytest uv run pytest
pipenv shell source .venv/bin/activate
pipenv lock uv lock
pipenv sync uv sync
pipenv update uv lock --upgrade
pipenv update requests uv lock --upgrade-package requests
pipenv graph uv tree

Tip

pipenv shell spawns a subshell. uv keeps the virtual environmentAn isolated folder where Python installs packages for one project, keeping them separate from other projects and your system Python. Learn more → in .venv at the project root. Activate it with source .venv/bin/activate (macOS/Linux) or .venv\Scripts\activate (Windows), or prefix commands with uv run instead of activating.

Learn More

Last updated on