> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/astral-sh/uv/llms.txt
> Use this file to discover all available pages before exploring further.

# uv pip compile

> Compile a requirements file to a locked format.

`uv pip compile` resolves dependencies and creates a locked requirements file. It is compatible with `pip-compile` from pip-tools but offers significantly faster performance.

## Usage

```bash theme={null}
# Compile requirements
uv pip compile requirements.in -o requirements.txt

# Compile pyproject.toml
uv pip compile pyproject.toml -o requirements.txt

# Compile with extras
uv pip compile pyproject.toml --extra dev -o requirements.txt

# Upgrade all packages
uv pip compile requirements.in --upgrade -o requirements.txt
```

## Arguments

### Input Sources

<ParamField body="src_file" type="path[]" required>
  Input files to compile.

  Supported formats:

  * `requirements.in` or `.txt`
  * `.py` files with inline metadata
  * `pylock.toml`
  * `pyproject.toml`, `setup.py`, `setup.cfg`

  Use `-` to read from stdin.

  ```bash theme={null}
  uv pip compile requirements.in
  uv pip compile pyproject.toml setup.cfg
  echo "requests" | uv pip compile -
  ```
</ParamField>

### Output Options

<ParamField body="-o, --output-file" type="path">
  Write compiled requirements to a file.

  If the file exists, its pinned versions are used as preferences during resolution (unless `--upgrade` is specified).

  ```bash theme={null}
  uv pip compile requirements.in -o requirements.txt
  uv pip compile pyproject.toml -o requirements.txt
  ```
</ParamField>

<ParamField body="--format" type="string">
  Output format: `requirements-txt` or `pylock`.

  Default: Inferred from `--output-file` extension, otherwise `requirements-txt`

  ```bash theme={null}
  uv pip compile requirements.in --format pylock -o pylock.toml
  ```
</ParamField>

### Constraints and Overrides

<ParamField body="-c, --constraint" type="path[]">
  Constrain package versions without requiring installation.

  ```bash theme={null}
  uv pip compile requirements.in -c constraints.txt
  ```

  Environment: `UV_CONSTRAINT`
</ParamField>

<ParamField body="--override" type="path[]">
  Override package versions, ignoring dependencies.

  ```bash theme={null}
  uv pip compile requirements.in --override overrides.txt
  ```

  Environment: `UV_OVERRIDE`
</ParamField>

<ParamField body="--exclude" type="path[]">
  Exclude packages from resolution.

  ```bash theme={null}
  uv pip compile requirements.in --exclude excludes.txt
  ```

  Environment: `UV_EXCLUDE`
</ParamField>

<ParamField body="-B, --build-constraint" type="path[]">
  Constrain build dependencies when building from source.

  ```bash theme={null}
  uv pip compile requirements.in --build-constraint build-constraints.txt
  ```

  Environment: `UV_BUILD_CONSTRAINT`
</ParamField>

### Optional Dependencies

<ParamField body="--extra" type="string[]">
  Include optional dependencies (extras) from `pyproject.toml`.

  ```bash theme={null}
  uv pip compile pyproject.toml --extra dev --extra test
  ```
</ParamField>

<ParamField body="--all-extras">
  Include all optional dependencies.

  ```bash theme={null}
  uv pip compile pyproject.toml --all-extras
  ```
</ParamField>

<ParamField body="--group" type="string[]">
  Include dependency groups from `pyproject.toml`.

  ```bash theme={null}
  uv pip compile pyproject.toml --group dev --group test
  ```
</ParamField>

### Resolver Options

<ParamField body="-U, --upgrade">
  Upgrade all packages to the latest compatible versions.

  ```bash theme={null}
  uv pip compile requirements.in --upgrade
  ```
</ParamField>

<ParamField body="-P, --upgrade-package" type="requirement[]">
  Upgrade specific packages while keeping others pinned.

  ```bash theme={null}
  uv pip compile requirements.in --upgrade-package requests --upgrade-package flask
  ```
</ParamField>

<ParamField body="--resolution" type="string">
  Resolution strategy: `highest`, `lowest`, or `lowest-direct`.

  Default: `highest`

  ```bash theme={null}
  uv pip compile requirements.in --resolution lowest
  ```

  Environment: `UV_RESOLUTION`
</ParamField>

<ParamField body="--prerelease" type="string">
  Pre-release handling: `disallow`, `allow`, `if-necessary`, `explicit`, or `if-necessary-or-explicit`.

  Default: `if-necessary-or-explicit`

  ```bash theme={null}
  uv pip compile requirements.in --prerelease allow
  ```

  Environment: `UV_PRERELEASE`
</ParamField>

<ParamField body="--fork-strategy" type="string">
  Version selection strategy: `requires-python` or `fewest`.

  Default: `requires-python`

  Environment: `UV_FORK_STRATEGY`
</ParamField>

<ParamField body="--no-deps">
  Only add explicitly listed packages, not their dependencies.

  ```bash theme={null}
  uv pip compile requirements.in --no-deps
  ```
</ParamField>

### Output Formatting

<ParamField body="--no-strip-extras">
  Include extras in output file.

  By default, uv strips extras as dependencies are already included.

  ```bash theme={null}
  uv pip compile requirements.in --no-strip-extras
  ```
</ParamField>

<ParamField body="--no-strip-markers">
  Include environment markers in output.

  ```bash theme={null}
  uv pip compile requirements.in --no-strip-markers
  ```
</ParamField>

<ParamField body="--no-annotate">
  Exclude comments indicating package sources.

  ```bash theme={null}
  uv pip compile requirements.in --no-annotate
  ```
</ParamField>

<ParamField body="--annotation-style" type="string">
  Annotation comment style: `line`, `split`.

  Default: `split`

  ```bash theme={null}
  uv pip compile requirements.in --annotation-style line
  ```
</ParamField>

<ParamField body="--no-header">
  Exclude the header comment from output.

  ```bash theme={null}
  uv pip compile requirements.in --no-header
  ```
</ParamField>

<ParamField body="--custom-compile-command" type="string">
  Custom command for header (for build script wrappers).

  ```bash theme={null}
  uv pip compile requirements.in --custom-compile-command "make requirements"
  ```

  Environment: `UV_CUSTOM_COMPILE_COMMAND`
</ParamField>

<ParamField body="--emit-index-url">
  Include `--index-url` and `--extra-index-url` in output.

  ```bash theme={null}
  uv pip compile requirements.in --emit-index-url
  ```
</ParamField>

<ParamField body="--emit-find-links">
  Include `--find-links` in output.

  ```bash theme={null}
  uv pip compile requirements.in --emit-find-links
  ```
</ParamField>

<ParamField body="--emit-build-options">
  Include `--no-binary` and `--only-binary` in output.

  ```bash theme={null}
  uv pip compile requirements.in --emit-build-options
  ```
</ParamField>

<ParamField body="--emit-index-annotation">
  Include index source in comments.

  ```bash theme={null}
  uv pip compile requirements.in --emit-index-annotation
  ```
</ParamField>

<ParamField body="--no-emit-package" type="package[]">
  Omit specific packages from output (but include dependencies).

  Equivalent to pip-compile's `--unsafe-package`.

  ```bash theme={null}
  uv pip compile requirements.in --no-emit-package setuptools
  ```
</ParamField>

### Hash Generation

<ParamField body="--generate-hashes">
  Include distribution hashes in output.

  ```bash theme={null}
  uv pip compile requirements.in --generate-hashes
  ```
</ParamField>

### Python Environment

<ParamField body="-p, --python" type="string">
  Python interpreter for building source distributions.

  Also determines minimum Python version unless `--python-version` is provided.

  ```bash theme={null}
  uv pip compile requirements.in --python 3.11
  uv pip compile requirements.in --python /path/to/python
  ```

  Environment: `UV_PYTHON`
</ParamField>

<ParamField body="--system">
  Use system Python instead of virtual environment.

  ```bash theme={null}
  uv pip compile requirements.in --system
  ```

  Environment: `UV_SYSTEM_PYTHON`
</ParamField>

<ParamField body="--python-version" type="version">
  Minimum Python version to support (e.g., `3.8` or `3.8.17`).

  ```bash theme={null}
  uv pip compile requirements.in --python-version 3.8
  ```
</ParamField>

<ParamField body="--python-platform" type="triple">
  Target platform triple (e.g., `x86_64-unknown-linux-gnu`).

  ```bash theme={null}
  uv pip compile requirements.in --python-platform x86_64-unknown-linux-gnu
  ```
</ParamField>

<ParamField body="--universal">
  Create a universal resolution for all platforms and Python versions.

  The specified `--python-version` is treated as a lower bound.

  Implies `--no-strip-markers`.

  ```bash theme={null}
  uv pip compile requirements.in --universal --python-version 3.8
  ```
</ParamField>

### Build Options

<ParamField body="--no-build">
  Don't build source distributions. Only use pre-built wheels.

  Alias for `--only-binary :all:`

  ```bash theme={null}
  uv pip compile requirements.in --no-build
  ```
</ParamField>

<ParamField body="--no-binary" type="package[]">
  Build specific packages from source.

  ```bash theme={null}
  uv pip compile requirements.in --no-binary numpy
  uv pip compile requirements.in --no-binary :all:
  ```
</ParamField>

<ParamField body="--only-binary" type="package[]">
  Only use pre-built wheels for specific packages.

  ```bash theme={null}
  uv pip compile requirements.in --only-binary pillow
  uv pip compile requirements.in --only-binary :all:
  ```
</ParamField>

<ParamField body="-C, --config-setting" type="key=value[]">
  Pass settings to the PEP 517 build backend.

  ```bash theme={null}
  uv pip compile requirements.in --config-setting="--build-option=--debug"
  ```
</ParamField>

<ParamField body="--config-settings-package" type="package:key=value[]">
  Pass package-specific settings to build backends.

  ```bash theme={null}
  uv pip compile requirements.in --config-settings-package="numpy:--with-lapack"
  ```
</ParamField>

<ParamField body="--no-build-isolation">
  Disable build isolation. Assumes build dependencies are already installed.

  ```bash theme={null}
  uv pip compile requirements.in --no-build-isolation
  ```

  Environment: `UV_NO_BUILD_ISOLATION`
</ParamField>

<ParamField body="--no-build-isolation-package" type="package[]">
  Disable build isolation for specific packages.

  ```bash theme={null}
  uv pip compile requirements.in --no-build-isolation-package numpy
  ```
</ParamField>

### Index Options

<ParamField body="--index" type="url[]">
  Package indexes to use (in addition to default).

  ```bash theme={null}
  uv pip compile requirements.in --index https://pypi.org/simple
  ```

  Environment: `UV_INDEX`
</ParamField>

<ParamField body="--default-index" type="url">
  Default package index (replaces PyPI).

  ```bash theme={null}
  uv pip compile requirements.in --default-index https://private.pypi.org/simple
  ```

  Environment: `UV_DEFAULT_INDEX`
</ParamField>

<ParamField body="-i, --index-url" type="url">
  Deprecated: Use `--default-index` instead.

  Environment: `UV_INDEX_URL`
</ParamField>

<ParamField body="--extra-index-url" type="url[]">
  Deprecated: Use `--index` instead.

  Environment: `UV_EXTRA_INDEX_URL`
</ParamField>

<ParamField body="-f, --find-links" type="path|url[]">
  Additional locations to search for packages.

  ```bash theme={null}
  uv pip compile requirements.in --find-links ./wheels
  ```

  Environment: `UV_FIND_LINKS`
</ParamField>

<ParamField body="--no-index">
  Ignore package indexes, only use `--find-links`.

  ```bash theme={null}
  uv pip compile requirements.in --no-index --find-links ./wheels
  ```
</ParamField>

<ParamField body="--index-strategy" type="string">
  Index selection strategy: `first-index`, `unsafe-first-match`, or `unsafe-best-match`.

  Default: `first-index`

  Environment: `UV_INDEX_STRATEGY`
</ParamField>

<ParamField body="--keyring-provider" type="string">
  Keyring provider for authentication: `disabled`, `subprocess`.

  Default: `disabled`

  Environment: `UV_KEYRING_PROVIDER`
</ParamField>

### Version Constraints

<ParamField body="--exclude-newer" type="date">
  Exclude packages uploaded after the specified date.

  ```bash theme={null}
  uv pip compile requirements.in --exclude-newer 2024-01-01
  uv pip compile requirements.in --exclude-newer "7 days"
  ```

  Environment: `UV_EXCLUDE_NEWER`
</ParamField>

<ParamField body="--exclude-newer-package" type="package=date[]">
  Exclude specific packages uploaded after dates.

  ```bash theme={null}
  uv pip compile requirements.in --exclude-newer-package "numpy=2024-01-01"
  ```
</ParamField>

<ParamField body="--link-mode" type="string">
  Link mode for build environments: `clone`, `copy`, `hardlink`, `symlink`.

  Default: `clone` on macOS/Linux, `hardlink` on Windows

  Environment: `UV_LINK_MODE`
</ParamField>

### uv Extensions

<ParamField body="--torch-backend" type="string">
  PyTorch backend: `cpu`, `cu126`, `cu124`, `cu121`, `cu118`, or `auto`.

  <Info>
    Preview feature. May change in future releases.
  </Info>

  ```bash theme={null}
  uv pip compile requirements.in --torch-backend cu126
  ```

  Environment: `UV_TORCH_BACKEND`
</ParamField>

<ParamField body="--no-sources">
  Ignore `tool.uv.sources` in `pyproject.toml`.

  Environment: `UV_NO_SOURCES`
</ParamField>

<ParamField body="--no-sources-package" type="package[]">
  Ignore sources for specific packages.

  Environment: `UV_NO_SOURCES_PACKAGE`
</ParamField>

### Cache Options

<ParamField body="--refresh">
  Refresh all cached data.

  ```bash theme={null}
  uv pip compile requirements.in --refresh
  ```
</ParamField>

<ParamField body="--refresh-package" type="package[]">
  Refresh cached data for specific packages.

  ```bash theme={null}
  uv pip compile requirements.in --refresh-package numpy
  ```
</ParamField>

## Examples

### Basic Compilation

```bash theme={null}
# Compile requirements.in
uv pip compile requirements.in -o requirements.txt

# Compile pyproject.toml
uv pip compile pyproject.toml -o requirements.txt

# Multiple input files
uv pip compile requirements.in dev-requirements.in -o requirements.txt
```

### With Extras

```bash theme={null}
# Compile with specific extras
uv pip compile pyproject.toml --extra dev -o requirements.txt

# Compile with all extras
uv pip compile pyproject.toml --all-extras -o requirements.txt

# Multiple extras
uv pip compile pyproject.toml --extra dev --extra test -o requirements.txt
```

### Upgrading Dependencies

```bash theme={null}
# Upgrade all packages
uv pip compile requirements.in --upgrade -o requirements.txt

# Upgrade specific packages
uv pip compile requirements.in --upgrade-package requests -o requirements.txt

# Upgrade multiple packages
uv pip compile requirements.in -P requests -P flask -o requirements.txt
```

### Universal Resolution

```bash theme={null}
# Create universal resolution for Python 3.8+
uv pip compile requirements.in --universal --python-version 3.8 -o requirements.txt

# Universal resolution keeps markers
uv pip compile requirements.in --universal -o requirements.txt
```

### With Constraints

```bash theme={null}
# Apply version constraints
uv pip compile requirements.in -c constraints.txt -o requirements.txt

# Override specific versions
uv pip compile requirements.in --override overrides.txt -o requirements.txt
```

### Hash Generation

```bash theme={null}
# Generate hashes for security
uv pip compile requirements.in --generate-hashes -o requirements.txt
```

### Custom Output Format

```bash theme={null}
# Output as pylock.toml
uv pip compile requirements.in --format pylock -o pylock.toml

# Without annotations
uv pip compile requirements.in --no-annotate -o requirements.txt

# With minimal output
uv pip compile requirements.in --no-header --no-annotate -o requirements.txt
```

### Custom Indexes

```bash theme={null}
# Use private index
uv pip compile requirements.in --index https://private.pypi.org/simple -o requirements.txt

# Include index URLs in output
uv pip compile requirements.in --emit-index-url -o requirements.txt
```

### Cross-Platform

```bash theme={null}
# Compile for specific Python version
uv pip compile requirements.in --python-version 3.8 -o requirements.txt

# Compile for specific platform
uv pip compile requirements.in --python-platform x86_64-unknown-linux-gnu -o requirements.txt
```

### Build Options

```bash theme={null}
# Don't build source distributions
uv pip compile requirements.in --no-build -o requirements.txt

# Build specific package from source
uv pip compile requirements.in --no-binary numpy -o requirements.txt
```

## pip-tools Compatibility

`uv pip compile` is designed to be compatible with `pip-compile` from pip-tools:

```bash theme={null}
# pip-compile command
pip-compile requirements.in

# Equivalent uv command
uv pip compile requirements.in -o requirements.txt
```

### Differences from pip-compile

1. **Performance**: uv is significantly faster (10-100x)
2. **Output file**: uv requires explicit `-o` flag; pip-compile infers it
3. **Markers**: uv strips markers by default; use `--no-strip-markers` for pip-compile behavior
4. **Extras**: uv strips extras by default; use `--no-strip-extras` for pip-compile behavior
5. **Resolution**: uv uses a more sophisticated resolver

### Migration from pip-compile

```bash theme={null}
# pip-compile (infers output)
pip-compile requirements.in

# uv equivalent (explicit output)
uv pip compile requirements.in -o requirements.txt

# With markers preserved
uv pip compile requirements.in --no-strip-markers -o requirements.txt
```

## Output Format

The default output is a `requirements.txt` file:

```txt theme={null}
# This file was autogenerated by uv via the following command:
#    uv pip compile requirements.in -o requirements.txt
certifi==2024.2.2
    # via requests
charset-normalizer==3.3.2
    # via requests
idna==3.6
    # via requests
requests==2.31.0
    # via -r requirements.in
urllib3==2.2.1
    # via requests
```

With `--format pylock`, output is in PEP 751 format:

```toml theme={null}
version = 1

[[package]]
name = "requests"
version = "2.31.0"
source = { url = "https://pypi.org/simple" }
# ...
```

## Related Commands

* [`uv pip install`](/cli/pip-install) - Install packages
* [`uv pip sync`](/cli/pip-sync) - Sync environment with lockfile
* [`uv lock`](/cli/lock) - Lock project dependencies
