Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 916
jesperk.eth Avatar asked May 11 '20 16:05

jesperk.eth


Video Answer


2 Answers

now its feasible to configure that on requirements.txt

--prefer-binary

<packages>
....

https://github.com/pypa/pip/pull/7996

like image 115
Oshan Wisumperuma Avatar answered Oct 21 '22 17:10

Oshan Wisumperuma


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

like image 23
jesperk.eth Avatar answered Oct 21 '22 19:10

jesperk.eth