pythonpipvirtualenvbuild-dependencies

Python pip rebuild requirements


Using a virtualenv with pip install and pip freeze is quite a nice way to work. All your requirements can be handled at the shell and at a later date another developer can rebuild things

pip install lib1
pip freeze > requirements.txt

# Do some development

# Oh I need this as well
pip install lib2
pip freeze > requirements.txt
# Another developer comes along
pip install -r requirements.txt

# They can carry on developer

However, if you then want to update your libraries thins are difficult (because you have all the dependencies in the freeze rather than just the packages you use).

Is there a way to work like this where but also update your libraries at a later date.

One approach is to use pip-tools and keep a requirements file (this is used internally by pipenv), but this isn't very "shelly"


Solution

  • My workflow avoids pip freeze. It goes:

    # Oh, I need lib1
    echo "lib1~=1.0" >> requirements.txt
    pip install -r requirements.txt
    
    # Oh, I need lib2
    echo "lib2~=3.0" >> requirements.txt
    pip install -r requirements.txt
    

    That way, requirements.txt contains only my direct dependencies, so hopefully it's much easier to maintain.