pip-compile

Text

Text

$ python -m pip install django
Collecting django
Using cached Django-5.0-py3-none-any.whl.metadata (4.2 kB)

Text

Text

$ python -m pip install django
Collecting django
Using cached Django-5.0-py3-none-any.whl.metadata (4.2 kB)
Collecting asgiref<4,>=3.7.0 (from django)
Using cached asgiref-3.7.2-py3-none-any.whl.metadata (9.2 kB)
Collecting sqlparse>=0.3.1 (from django)
Using cached sqlparse-0.4.4-py3-none-any.whl (41 kB)
Using cached Django-5.0-py3-none-any.whl (8.1 MB)
Using cached asgiref-3.7.2-py3-none-any.whl (24 kB)
Installing collected packages: sqlparse, asgiref, django
Successfully installed asgiref-3.7.2 django-5.0 sqlparse-0.4.4

Text

Text

$ python -m pip freeze > requirements.txt

Text

Text

asgiref==3.7.2
Django==5.0
sqlparse==0.4.4

requirements.txt

What's the problem?

  1. Your project's dependency or the dependency of a dependency?
  2. You have to pip freeze every time you add sth.
  3. If you change a packages version, dependencies of that package are still pinned to the old version

A solution...

pip-compile

pip-compile is included in the pip-tools package

$ python -m pip install pip-tools

requirements.in

django==5.0

requirements.in

django==5.0
$ pip-compile
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile
#
asgiref==3.7.2
# via django
django==5.0.1
# via -r requirements.in
sqlparse==0.4.4
# via django

Further reading...

pip-sync

pip-lock

References

Boost your django DX (book)

by Adam Johnson

deck

By halitcelik

deck

  • 20