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

Add --prefix flag for uv pip install #3076

Closed
jorng opened this issue Apr 16, 2024 · 11 comments · Fixed by #4085
Closed

Add --prefix flag for uv pip install #3076

jorng opened this issue Apr 16, 2024 · 11 comments · Fixed by #4085
Labels
compatibility Compatibility with a specification or another tool

Comments

@jorng
Copy link

jorng commented Apr 16, 2024

When performing multi-stage Docker builds, the --prefix flag is very useful to create an isolated install of dependencies that can then be copied to the final stage of a build.

Example with pip:

FROM python AS builder
# Possibly install prerequisites, gcc, etc, that aren't needed in runtime
COPY requirements.txt ./
RUN pip install -r requirements.txt --prefix /install
# Do other installs / builds...

FROM python:slim
COPY --from=builder /install /usr/local
# Other stuff as needed

Related:

Notably, this may need to be used in association with --system or --python to specify which python executables are pointed to.

@zanieb zanieb added the compatibility Compatibility with a specification or another tool label Apr 16, 2024
@ericmarkmartin
Copy link
Contributor

We have a use for this at Jane Street. I have a first draft patch that seems to work.

Still need to write tests and think about windows though

@zanieb
Copy link
Member

zanieb commented Jun 5, 2024

Is --target insufficient?

@charliermarsh
Copy link
Member

What’s the use-case?

@ericmarkmartin
Copy link
Contributor

ericmarkmartin commented Jun 6, 2024

Is --target insufficient?

Target dumps everything into the specified dir. Prefix implies a certain Scheme. Concretely, jupyterlab, for instance, includes plugins and such that should go into share, but --target will dump that stuff alongside the source.

From the linked doc:

The “prefix scheme” is useful when you wish to use one Python installation to perform the build/install ..., but install modules into the third-party module directory of a different Python installation (or something that looks like a different Python installation).

@charliermarsh
Copy link
Member

What is the workflow though that demands --prefix as opposed to installing into an arbitrary Python environment via --python? --prefix has its own problems -- IIUC, scripts etc. will reference the parent Python interpreter, not the --prefix Python interpreter.

@charliermarsh
Copy link
Member

(By the way, I don't think --prefix is too hard to support, and I'm not really against it -- I just want to make sure that it's justified.)

@charliermarsh
Copy link
Member

Do you want advice on your draft? My hope is that you can just change Interpreter::layout to return paths joined against self.virtualenv rather than self.scheme.

@charliermarsh
Copy link
Member

I put up a PR here with basic support: #4085.

@ericmarkmartin
Copy link
Contributor

Oh wow that was quick. I was about to put mine up but will take a look at this first

@charliermarsh
Copy link
Member

Was hoping to save you some trouble, sorry if I stepped on your toes.

@ericmarkmartin
Copy link
Contributor

Haha no worries--thanks for the help!

charliermarsh added a commit that referenced this issue Jun 6, 2024
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

Successfully merging a pull request may close this issue.

4 participants