rmorshea
rmorshea

Reputation: 852

How to Install the Minimum Version of a Dependency

Question

How can I install the lowest possible version of a dependency using pip (or any other tool for that matter) given some set of version specifiers. So if I were to specify requests >=2.0, <3.0 I would actually want to install requests==2.0.

Motivation

When creating Python packages you probably want to enable users to interact with it in a variety of environments. This means that you'll often claim to support many versions of a given dependency. For example one might claim that their package supports requests>=2.0. The problem here is that to responsibly make this claim we need some way of testing that our package works both with requests==2.0 but also the latest version and anything in between.

Unfortunately I don't think there's a good solution for testing one's support for all possible combinations of dependencies, but you can at least try to test the maximum and minimum versions of your dependencies.

To solve this problem I usually create a requirements.min.txt file that contains the lowest version of all my dependencies so that I can install those when I want to test that my changes haven't broken my support for older versions. Thus, if I claimed to support requests>=2.0 my requirements.min.txt files would have requests==2.0.

This solution to the problem of testing against one's minimum dependency set feels messy though. Has anyone also found a good solution?

Upvotes: 14

Views: 1676

Answers (2)

Mike666
Mike666

Reputation: 459

Said feature not yet exists in pip (at time of writing).

However, there is an ongoing discussion https://github.com/pypa/pip/issues/8085 and PR https://github.com/pypa/pip/pull/11336 to implement it as --version-selection=min.

I hope it will be merged eventually.

Upvotes: 2

Derek Eden
Derek Eden

Reputation: 4618

not a full answer, but something that might help you get started...

pip install pkg_name_here==

this will output all versions available on pip which you can then redirect to a string/list and split out the versions, then install any that fall between you min/max supported versions using some kind of conditional statement

Upvotes: 2

Related Questions