Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --prefer-binary in requirements.txt files #1794

Open
stinodego opened this issue Feb 21, 2024 · 13 comments
Open

Support --prefer-binary in requirements.txt files #1794

stinodego opened this issue Feb 21, 2024 · 13 comments
Labels
compatibility Compatibility with a specification or another tool

Comments

@stinodego
Copy link

pip supports including a --prefer-binary flag in a requirements.txt like so:

--prefer-binary

polars
ruff

However, uv pip install does not support this:

$ uv pip install -r requirements.txt 
error: Unexpected '-', expected '-c', '-e', '-r' or the start of a requirement in `requirements.txt` at position 0

This is on version 0.1.6.

It would be nice if this syntax could be supported!

@charliermarsh
Copy link
Member

I think we support --no-binary and --only-binary on the command-line, but not --prefer-binary (and none are supported in requirements.txt right now).

@zanieb zanieb added the compatibility Compatibility with a specification or another tool label Feb 21, 2024
@zanieb
Copy link
Member

zanieb commented Feb 21, 2024

We already always prefer binaries, right? I believe that's why we omitted the flag.

I'm not sure these belong in the requirements file. Just wondering, why is this preferred (other than compatibility)?

@stinodego
Copy link
Author

We already always prefer binaries, right? I believe that's why we omitted the flag.

I'm not sure what uv does. I know that pip will prefer to install the latest version, even if there is no binary for it. Using --prefer-binary will make it install an older version if that means it doesn't have to build from source.

I'm not sure these belong in the requirements file. Just wondering, why is this preferred (other than compatibility)?

Honestly, I also don't know if it belongs there. I reported this because uv wants to be a drop-in replacement for pip and I ran into this.

In general though, the benefit of having this setting in the requirements file itself is that you don't have to specify this setting in all your installers, e.g. CI / Makefile / Dockerfile / ... . The setting is in one place, together with the requirements. That does make some sense.

@charliermarsh charliermarsh self-assigned this Apr 4, 2024
@charliermarsh
Copy link
Member

@zanieb -- I think --prefer-binary goes even further, in that it will prefer an older version of a package with a wheel over a newer version without one.

@charliermarsh charliermarsh removed their assignment Apr 8, 2024
@njzjz
Copy link

njzjz commented Apr 21, 2024

I am +1 for this feature. A use case is that h5py linux_aarch64 wheels are available in v3.10 but not available in v3.11 (see h5py/h5py#2408). When I use pip, I can set export PIP_PREFER_BINARY=1 in the CI service to let pip install v3.10 wheels. However, ux doesn't have such an option. The default behavior is to install from v3.11 source, which will fail as it requires HDF5 library to be installed in advance.

We need uv to support the UV_PREFER_BINARY environmental variable.

@zanieb
Copy link
Member

zanieb commented Apr 21, 2024

@njzjz Is there a reason that this flag is better than just adding a pin or additional constraint?

@stinodego
Copy link
Author

You may not want to pin a dependency to take advantage of the latest updates whenever they come out. However, you generally also want to avoid compiling packages from source if binaries are available. This setting unifies the two.

Constraints may not work, or I would have to micromanage these for each dependency / platform depending on the wheels that are available. A single --prefer-binary takes care of all that.

@njzjz
Copy link

njzjz commented Apr 21, 2024

This flag will also ensure the CI is not broken in the future when a new release doesn't contain the binary. Otherwise, we need to add the pin manually every time.

@notatallshaw-gts
Copy link

notatallshaw-gts commented May 8, 2024

My use case for --prefer-binary is in the equivalent of a pip compile scenario, I am generating new pinned versions of my entire environment from my requirements.

Ideally I would use --only-binary but there are a handful of packages where this is still not possible, and it's not practical to go through my ~200 transitive dependencies and see which ones have not yet releases a wheel for their latest release every time I update the pinned versions.

@notatallshaw-gts
Copy link

May be helpful for other users, my use case is now solved by #4063 / #4067.

I can specify that wheels should always be picked with --only-binary :all: and override that to have specific packages use sdists with --no-binary <package>

@njzjz
Copy link

njzjz commented Jun 12, 2024

I can specify that wheels should always be picked with --only-binary :all: and override that to have specific packages use sdists with --no-binary <package>

I created #4291 for the environment variable support request.

@tpgillam
Copy link

tpgillam commented Aug 3, 2024

I agree that this would be useful for compatibility purposes; I'm setting up the matplotlib test environment, and was hoping to use uv pip sync. However it doesn't work due to the --prefer-binary here:

https://github.com/matplotlib/matplotlib/blob/109ab93ba2e687a7b805cb0075efa52ef4e61cde/requirements/testing/extra.txt#L3

> uv pip sync requirements/dev/dev-requirements.txt
error: Error parsing included file in `requirements/dev/dev-requirements.txt` at position 79
  Caused by: Unexpected '-', expected '-c', '-e', '-r' or the start of a requirement at requirements/dev/../testing/extra.txt:3:1

@notatallshaw-gts
Copy link

notatallshaw-gts commented Aug 4, 2024

It would be good if it was in the pip the compatibility document: https://github.com/astral-sh/uv/blob/main/PIP_COMPATIBILITY.md

I guess anyone could submit a PR for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with a specification or another tool
Projects
None yet
Development

No branches or pull requests

6 participants