Operations Research

Logo

A site for hosting software and data repositories associated with papers appearing in the journal _Operations Research_

View source on GitHub

Dependency Management in Python

Python offers several methods for specifying project dependencies, each suited for different use cases:

1. requirements.txt

The traditional and simplest approach:

requests==2.28.1
numpy>=1.20.0
pandas~=1.5.0

2. setup.py / setup.cfg

For creating installable packages:

setup(
    name="mypackage",
    install_requires=[
        "requests>=2.20.0",
        "numpy",
    ],
    extras_require={
        "dev": ["pytest", "black"],
    }
)

3. pyproject.toml

The modern, standardized approach (PEP 518, 621):

[project]
dependencies = [
    "requests>=2.20.0",
    "numpy>=1.20",
]

[project.optional-dependencies]
dev = ["pytest", "black"]

4. Pipfile / Pipfile.lock

Used by Pipenv:

[packages]
requests = "*"

[dev-packages]
pytest = "*"

5. poetry.lock / pyproject.toml

Poetry’s approach combines both:

6. Conda environment.yml

For conda environments:

dependencies:
  - python=3.9
  - numpy
  - pip:
    - requests

Common Version Specifiers


Current trend: The ecosystem is moving toward pyproject.toml as the standard for all Python projects, with lock files (Poetry, PDM, or pip-tools) for reproducible environments.