Skip to content

Support copy or hardlink python interpreter when creating venv #6782

@amartani

Description

@amartani

Currently, when creating a venv, uv always symlinks the python interpreter. Example:

$ uv venv --python=3.12 /venv
$ ls -l /venv/bin
...
lrwxrwxrwx 1 root root   25 Aug 28 23:53 python -> /root/.local/share/uv/python/cpython-3.12.5-linux-aarch64-gnu/bin/python3.12
lrwxrwxrwx 1 root root    6 Aug 28 23:53 python3 -> python
lrwxrwxrwx 1 root root    6 Aug 28 23:53 python3.12 -> python

The original python -m venv supports either symlink or copy (with --symlinks / --copies flag). It would be great if uv also supported the same, similar to how --link-mode exists for uv pip.

My main use case is for using a docker multi-stage build where one of the stages builds the venv and then other stages can just copy the entire venv folder; example Dockerfile:

FROM base as venv-builder

RUN uv venv --python=3.12 /venv
RUN uv pip install --python /venv/bin/python ...

FROM base as final-image

# Do other things here

COPY --from=venv-builder /venv /venv

This use case currently breaks as the symlink ends up pointing to a python binary that does not exist in the final image. For this use case, the ideal behavior would be that the main /venv/bin/python binary was copied or hardlinked from the external binary and python3/python3.12 continued to be relative symlinks.

Tested on uv version 0.4.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliRelated to the command line interfaceenhancementNew feature or improvement to existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions