Constraints files are requirements files that only control which version of a requirement is installed, not whether it is installed or not.
In a previous post, I talked about ditching pip freeze because it didn't work well with second-level dependencies (especially cross-platform). I found an even better workflow where I use a requirements.txt and a constraints.txt file together. Check out the code in this commit.
requirements
├── constraints.txt
└── requirements.txtJust add a second flag to pip install.
python3 -m pip install -r requirements.txt -c constraints.txtInside requirements.txtare packages blogthedata directly uses.
# requirements.txt
black
Brotli
chromedriver-autoinstaller
coverage
Django
...Constraints.txt includes everything in requirements.txt plus sub-dependencies
# constraints.txt
black==22.3.0
Brotli==1.0.9
cachetools==5.2.0
certifi==2022.6.15
cffi==1.15.1
...When used together, we are instructing pip to install everything in requirements.txt with the constraint that if anything is installed that is listed in constraints.txt, use the pinned version.
Now I can be certain sub-dependencies won't break my app without requiring that the sub-dependencies be installed.
Comments
- No comments yet.

John Solly
A hands-on AI practitioner who transitioned to a CTO role to broaden my impact.
Most of my career has been dedicated to developing spatial systems at Esri, startups, and federal agencies. Currently, I lead technology strategy for Leidos' Health IT division, supporting agencies such as SSA, VA, and HHS.
My primary focus is the convergence of spatial computing and AI, enabling machines to interpret the physical world and applying these capabilities to meaningful missions.
Please reach out if you are interested in spatial systems or advancing AI within the federal government.




0