Calmcode - pip-tools: introduction

Requirements files can cause issues

1 2 3 4 5

When you're installing packages for your project in Python you may have found yourself creating a requirements.txt file. These files can contain all of your dependencies and are a convenient way to pin your required versions of your dependencies.

You could have one such file with the following contents:

scikit-learn

Then, you could run your pip-command via:

python -m pip install -r requirements.txt

This would install scikit-learn via the requirements file.

Downside

In general, it's not a great practice to have a requirements file without a version number for each package. So instead you might consider doing something like this instead:

scikit-learn==1.4.0

This is better, but we should also consider the dependencies of scikit-learn. So maybe you'd like to add numpy and scipy to this file as well? Technically there's nothing wrong with that, but it can be a bit strange to hard pin dependencies if you're not using them directly.

Stuff like this can get very tricky when you have many dependencies and at some point you may find yourself looking for a tool that helps you with this. We've found that pip-tools is a nice tool to consider here, so we've made a small course about it.