How can I use --prefer-binary with pip in Python 3?

Viewed 9866

In Python 2 I can install a set of packages via pip preferring binary packages over source packages (meaning: fallback to source if binary not found) with:

(1) pip install --prefer-binary -r requirements.txt

In Python 3 I can do this with:

(2) pip3 install --only-binary=:all: -r requirements.txt

But (1) is not exactly equal to (2) since the former says:

Prefer binaries when installing; but if I don't find a binary option, then I'll go with source.

The latter says:

I will fail if no binaries are found; don't even try from source.

So, from the docs it seems that one solution could be to just manually enter each package which should be considered for source installation - meaning: the "only-binary" flag can be provided multiple times on the command line and can thus handle special-cases like that (by emptying it out, or giving specific package names to the binary packages). This answer details, to some extent, that approach: Make pip download prefer to download source-distributions (not wheels).

However, I have a large number of both types of packages so I need an automated way like the (1) approach.

Question: How can I get a similar automated behavior as (1) but in Python/pip 3?

Solution: Pip is not Python - upgrade pip to vs. 20.X and use --prefer-binary.

2 Answers

Solution: upgrade pip to vs. 20.X and use --prefer-binary

Related