Python 2.7¶
This section introduces the Python 2.7 packaging workflow built around pip,
setup.py, and requirements.txt, using a small command-line project to show
how pinned dependency files improved reproducibility.
Applied Project¶
Project Setup¶
The applied project is Historic Calculator, release 4.0.0. This snapshot is set in 2010, the release year of Python 2.7, and contains the historic_calculator package plus the hist_calc command-line script.
Run the Project¶
Application commands are documented in the section README.
Background¶
This project belongs to the Python 2.7 era that began in 2010, when pip and requirements.txt became the practical packaging workflow for many teams. The common layout paired setup.py with a pinned requirements file for:
- Declaring abstract package metadata and entry points
- Recording install-time runtime dependencies
- Pinning a concrete dependency set for repeatable installs
- Building source distributions for release
The setup.py file keeps the package metadata, abstract runtime dependency, and console-script registration:
setup(
name="historic_calculator",
version="4.0.0",
description="A tiny vector calculator using NumPy and setuptools.",
package_dir={"": "src"},
packages=["historic_calculator"],
install_requires=[
"numpy",
],
entry_points={
"console_scripts": [
"hist_calc = historic_calculator.main:main_cli",
],
},
)
namegives the distribution its package name.versionrecords the release number that build and install commands use.descriptionadds a short human-readable project summary to the package metadata.package_dirmaps packages to thesrcdirectory instead of the project root.packageslists the Python package included in the distribution.install_requiresrecords the abstract NumPy runtime dependency.entry_pointsregisters thehist_calccommand throughconsole_scripts.
Dependency Management¶
Overview¶
pip and requirements.txt made dependency installation more practical, but the model still had important limits:
- ⚠️
requirements.txtwas a pinned install input, not a complete lockfile with hashes. - ⚠️ Environment isolation was still a separate concern and was not provided by
pipitself. - ⚠️ Older pip behavior lacked the modern resolver used by current Python workflows.
Runtime and build dependencies¶
Use Dockerfile.devEnv for the Python 2.7 development environment. It keeps the historical interpreter, pip-era tooling, and build tooling isolated from the host machine.
NumPy replaces the earlier Numeric packages as the runtime component for array-style calculations. requirements.txt pins the exact NumPy version, so pip install -r requirements.txt can reproduce the dependency set more reliably than the manual download steps used in earlier sections.
Install the pinned runtime dependencies:
This installs the concrete dependency set for the Python 2.7 workflow before the project package is installed.
Build the package¶
Build the source distribution:
The era predates PEP 427 wheels, so the source distribution is the canonical artifact.
Install the package¶
Install the project itself: