Resolve pip dependency conflicts by intelligently removing problematic packages
Project description
pipreq-distill
Resolve pip dependency conflicts by intelligently removing problematic packages.
When pip install fails with dependency conflicts, pipreq-distill queries PyPI to find the largest possible collection of compatible packages by removing the oldest and most problematic dependencies.
Installation
pip install pipreq-distill
Or with uv:
uv pip install pipreq-distill
Usage
Basic Usage
# From requirements.txt to resolved.txt
pipreq-distill --input requirements.txt --output resolved.txt
# From stdin to stdout
cat requirements.txt | pipreq-distill > resolved.txt
# Dry run (show what would be removed)
pipreq-distill --input requirements.txt --dry-run
pyproject.toml Support
# Process pyproject.toml dependencies
pipreq-distill --input pyproject.toml --output pyproject.toml --format pyproject
# Process optional dependencies
pipreq-distill --input pyproject.toml --group optional.dev --dry-run
# Update in-place
pipreq-distill --input pyproject.toml --output pyproject.toml
Protect Specific Packages
# Never remove requests or flask
pipreq-distill --input requirements.txt --keep "requests,flask"
JSON Output
# Get structured output for scripting
pipreq-distill --input requirements.txt --json-output
Output:
{
"kept": ["flask==2.3.0", "requests==2.31.0"],
"removed": [
{"name": "old-pkg", "version": "1.0.0", "score": 150.5}
],
"kept_count": 2,
"removed_count": 1
}
How It Works
- Fetches package metadata from PyPI (with caching)
- Extracts dependencies from wheels or source distributions
- Detects version conflicts between packages
- Scores packages for removal based on:
- Conflict involvement (packages in more conflicts score higher)
- Reverse dependencies (packages with fewer dependents score higher)
- Package age (older packages score higher)
- Dependency age (packages depending on old packages score higher)
- Iteratively removes the highest-scoring package until no conflicts remain
- Outputs the largest possible set of compatible packages
CLI Options
| Option | Description | Default |
|---|---|---|
--input |
Input file (requirements.txt or pyproject.toml) | stdin |
--output |
Output file | stdout |
--format |
Format: auto, requirements, pyproject |
auto |
--group |
Dependency group for pyproject.toml | dependencies |
--keep |
Comma-separated packages to protect | None |
--dry-run |
Show what would be removed | False |
--json-output |
Output as JSON | False |
--verbose |
Show detailed progress | False |
--timeout |
PyPI request timeout (seconds) | 30 |
--max-concurrent |
Max concurrent PyPI requests | 20 |
Example
Given conflicting requirements:
aliyun-python-sdk-core>=2.16.0
jmespath>=1.0.1
Running:
$ pipreq-distill --input requirements.txt --verbose
Parsed 2 requirements
Fetching 2 packages in parallel...
Fetched 2 packages successfully
Iteration 1: 1 conflicts in 1 cluster(s)
Removing aliyun-python-sdk-core (score: 641.4)
Resolved to 1 compatible packages
jmespath==1.0.1
The tool identified that aliyun-python-sdk-core requires jmespath<1.0.0, which conflicts with jmespath>=1.0.1. Since aliyun-python-sdk-core is older and has the conflicting requirement, it was removed.
Dependency Groups
For pyproject.toml, you can specify different dependency groups:
dependencies- PEP 621 project.dependencies (default)optional.dev- project.optional-dependencies.devoptional.test- project.optional-dependencies.testdev- tool.uv.dev-dependencies
Caching
PyPI responses are cached in $TMPDIR/pipreq_distill_cache for 24 hours to speed up repeated runs.
Limitations
- Assumes you want the latest compatible versions
- Conditional dependencies (platform-specific markers) are simplified
- Uses a greedy algorithm (not guaranteed globally optimal)
- May download wheels/sdists for packages missing JSON metadata
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pipreq_distill-0.1.0.tar.gz.
File metadata
- Download URL: pipreq_distill-0.1.0.tar.gz
- Upload date:
- Size: 35.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.12 {"installer":{"name":"uv","version":"0.9.12"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7decf1424c322426bbb4fa653a43043ecb702a41e53886c5a1ca7d5638583835
|
|
| MD5 |
d8cf4403c132ae1fc78e49e676d04f37
|
|
| BLAKE2b-256 |
1cc94578fa80519e65b02819dfab7f0a87e1145acfcc9c306d5c05a4e739cfac
|
File details
Details for the file pipreq_distill-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pipreq_distill-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.12 {"installer":{"name":"uv","version":"0.9.12"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f64bb7f93d4fa6403ce828887886683ea89a632892f6508732859f8b255e7ee8
|
|
| MD5 |
b037aa557e8f46f0278e0aa2bea6d78e
|
|
| BLAKE2b-256 |
71242a6e399fadad529484964016abde61046bd692f9bb68f12eda9adc22aca9
|