Scripts2026年9月12日·1 分钟阅读

pip-tools — Python Dependency Pinning and Compilation

pip-tools provides pip-compile and pip-sync commands that turn loose requirements into fully pinned, reproducible lock files for Python projects.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
pip-tools Dependency Manager
直接安装命令
npx -y tokrepo@latest install eead8ecf-ae4a-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

pip-tools bridges the gap between loosely specified Python dependencies and fully reproducible installs. It compiles abstract requirements into concrete, pinned versions and then synchronizes a virtual environment to match, ensuring consistent builds across development, CI, and production.

What pip-tools Does

  • Resolves dependency trees from high-level requirement specifications into pinned versions
  • Generates requirements.txt files with exact versions and hashes for every transitive dependency
  • Synchronizes a virtual environment to match the lock file, removing packages not listed
  • Supports multiple output files for separating dev, test, and production dependencies
  • Integrates with existing pip workflows without requiring a new project format

Architecture Overview

pip-tools consists of two commands. pip-compile reads .in files containing abstract dependency specifications, resolves the full transitive dependency tree using pip's resolver, and writes a .txt file with pinned versions. pip-sync reads the pinned file and adjusts the active virtual environment to match exactly, installing missing packages and uninstalling extras. The resolution process respects constraints files, extras, and platform markers, producing deterministic output suitable for locking.

Self-Hosting & Configuration

  • Install pip-tools into your virtual environment or globally via pipx
  • Create requirements.in files listing direct dependencies with version ranges
  • Run pip-compile to generate the pinned requirements.txt lock file
  • Use pip-sync to install exactly the pinned versions, removing unlisted packages
  • Add --generate-hashes to pip-compile for supply-chain verification via hash checking

Key Features

  • Deterministic lock file generation from abstract dependency specifications
  • Hash-based verification support for supply-chain security
  • Layered requirements with constraint files for separating environments
  • Compatible with pip's native resolver and existing requirements.txt format
  • Works alongside any virtual environment tool (venv, virtualenv, conda)

Comparison with Similar Tools

  • Poetry — Full project manager with its own pyproject.toml lock format; heavier but more integrated
  • PDM — PEP 621-compliant manager with its own lock file; good for modern Python packaging
  • uv — Rust-based pip replacement with fast resolution; overlapping compile/sync features
  • pip freeze — Captures installed state but does not resolve from abstract specs or manage sync
  • Pipenv — Combines pip and virtualenv with a Pipfile.lock; slower resolution, less flexible layering

FAQ

Q: Can pip-tools work with pyproject.toml? A: Yes. pip-compile can read dependencies from pyproject.toml and write the pinned output to requirements.txt.

Q: How do I manage dev vs production dependencies? A: Create separate .in files (requirements.in, dev-requirements.in) and compile each to its own .txt file. Use constraint references to keep versions aligned.

Q: Does pip-sync remove packages not in the requirements file? A: Yes. pip-sync uninstalls any package in the environment that is not listed in the pinned requirements file, except pip, setuptools, and pip-tools itself.

Q: How do I upgrade a single dependency? A: Run pip-compile --upgrade-package=flask to re-resolve only that package while keeping others pinned.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产