Skip to content

How to export requirements.txt from a uv project

If a deployment tool requires requirements.txt, generate it from uv’s uv.lock. Keep managing dependencies in pyproject.toml; regenerate the exported file whenever dependencies change.

Prerequisites

  • uv installed.
  • An existing uv project with a current lockfileA file that records the exact version of every installed package, so everyone working on the project gets identical installs. (uv.lock). Run the commands from the directory containing pyproject.toml.

Export the locked dependencies

uv export --locked --format requirements-txt -o requirements.txt

uv writes requirements.txt and prints its contents. The file includes exact dependency versions and hashes; --locked fails if uv.lock needs updating. Resolve that mismatch with the project’s normal lockfile update workflow before exporting again.

The default export includes the project’s default dependency groups, normally dev. A packaged project also appears as -e ., an editable install of the current directory. A bare project without a build system does not need that entry.

Export dependencies for deployment

To omit all default groups and the project itself:

uv export --locked --no-default-groups --no-emit-project --format requirements-txt -o requirements.txt

The rewritten file contains the project’s runtime dependencies, including transitive dependenciesA package your dependency depends on. When you install requests, its own dependencies (urllib3, certifi, etc.) are transitive dependencies. , without the root project’s -e . entry. Use this when the deployment system handles application code separately. --no-emit-project retains the project’s dependencies; it does not remove other local path dependencies.

--no-dev excludes only the dev group. Use --no-default-groups when production must exclude every configured default group.

Include a named group

If the project declares a test group, export runtime dependencies plus that group:

uv export --locked --no-default-groups --group test --no-emit-project --format requirements-txt -o requirements-test.txt

uv writes and prints requirements-test.txt with the runtime and test dependencies. Replace test with the group’s name in pyproject.toml; optional extras use --extra instead.

Keep hashes and platform conditions

Exports include hashes by default. Keep them for hash-checked installs; add --no-hashes only if the receiving tool cannot parse them.

Dependencies with platform or Python conditions retain environment markers, such as ; sys_platform == 'win32'. The installer selects matching entries on the target machine. This preserves the lockfile’s supported environments; it does not make an unsupported dependency work on every platform.

Last updated on