Migrated a Python project from pip and requirements.txt to Poetry to resolve dependency conflicts and ensure reproducible builds. The update addressed version inconsistencies, missing transitive dependencies, and manual virtual environment management.
Issue
The project experienced:
- Dependency conflicts due to
pip’s lack of dependency resolution tree, causing version mismatches. - Non-reproducible builds as
requirements.txtonly listed direct dependencies, leaving transitive dependencies unresolved. - Manual virtual environment inconsistencies, leading to system-wide package conflicts and environment mismatches.
Culprit
- Lack of Dependency Resolution:
pipinstalls packages sequentially without verifying the entire dependency graph, causing conflicts. - No Lock File Mechanism:
requirements.txtlacked a mechanism to pin exact versions of transitive dependencies. - Manual Virtual Environment Management: Developers had to manually create and activate virtual environments, leading to inconsistencies.
- Version Range Ambiguity: Loose version specifications (e.g.,
transformers>=4.0.0) allowed incompatible minor/patch versions to be installed.
Solution
- Poetry Initialization: Set up
pyproject.tomlwith strict Python version constraints and configured in-project virtual environments (.venv/). - Dependency Migration: Migrated all 13 packages from
requirements.txttopyproject.tomlwith exact version pins and generated apoetry.lockfile for reproducibility. - Virtual Environment Management: Automated
.venv/creation in the project root, ensuring Python 3.14 environments with all dependencies isolated. - Documentation Updates: Replaced pip workflows with Poetry commands (e.g.,
poetry installinstead ofpip install -r requirements.txt).
The migration maintained backward compatibility by keeping an auto-generated requirements.txt while providing all benefits of Poetry’s deterministic dependency resolution.