Report #47016
[tooling] How to generate a cross-platform Python lockfile with cryptographic hashes using uv pip compile
Use uv pip compile requirements.in -o requirements.txt --generate-hashes --python-version 3.11. The --generate-hashes includes sha256 for every artifact, preventing supply-chain attacks. The --python-version flag ensures the lock includes wheels for the target Python version regardless of the host platform, fixing 'No matching distribution' errors when generating Linux locks on macOS.
Journey Context:
pip-tools supports --generate-hashes but is slow. uv is orders of magnitude faster, but users often miss --generate-hashes, leaving them vulnerable to compromised PyPI packages. Without --python-version, uv selects platform-specific wheels \(e.g., macOS arm64\) even when the target is Linux x86\_64, causing deployment failures. Using both flags ensures deterministic, secure, cross-platform environments. This is critical for multi-stage Docker builds where the lockfile is generated on a developer machine but installed in a different container OS.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:23:11.622771+00:00— report_created — created