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

Allow sync to install to system python #7748

Closed
nhumrich opened this issue Sep 27, 2024 · 5 comments
Closed

Allow sync to install to system python #7748

nhumrich opened this issue Sep 27, 2024 · 5 comments
Labels
duplicate This issue or pull request already exists question Asking for clarification or support

Comments

@nhumrich
Copy link

In docker environments, it's quite common to install all python packages to the system. Virtual environments are not needed because the current project is the only thing installed.

The docker documentation for UV recommends that you use the venv entrypoint for all container commands:

CMD ["/app/.venv/bin/python"]

However, this makes migrating to UV a bit harder when so many things already reference "python" directly in.

Also, using a virtual environment in these situations complicates the container, because devs now have to remember to use the .venv python always.

Would it be possible to install into the system during uv sync somehow. I assumed --python-preference only-system would do this, but that doesn't seem to prevent the creating of a virtual environment. uv pip install support --system, so its sort of strange that sync does not.

My current workaround is doing this in the dockerfile instead:

RUN --mount=from=ghcr.io/astral-sh/uv,source=/uv,target=/bin/uv \
    uv pip compile pyproject.toml -o requirements.txt && \
    uv pip install -r requirements.txt --system
@zanieb
Copy link
Member

zanieb commented Sep 28, 2024

See UV_PROJECT_ENVIRONMENT and #6834

@zanieb zanieb added question Asking for clarification or support duplicate This issue or pull request already exists labels Sep 28, 2024
@zanieb zanieb closed this as completed Oct 21, 2024
@nhumrich
Copy link
Author

nhumrich commented Oct 22, 2024

@zanieb maybe I am misunderstanding, but it appears as if UV_PROJECT_ENVIRONMENT wants the location of a virtualenv.

The intent is not to tell UV to use an existing virtual environment, but to use the system directly.

The docs also say:

uv sync will remove extraneous packages from the environment by default and, as such, may leave the system in a broken state.

This is not wanted. I would conclude that this feature request does not appear to be the same as the UV_PROJECT_ENVIRONMENT feature.

@zanieb
Copy link
Member

zanieb commented Oct 22, 2024

uv sync will remove extraneous packages from the environment by default and, as such, may leave the system in a broken state.

You can use --inexact then, but it still might change package versions if it needs to — which is the problem with using a system environment generally. Why are you using uv sync to a system environment if you don't have control over the environment?

@nhumrich
Copy link
Author

@zanieb I do have control over the environment. Its a docker container.

@zanieb
Copy link
Member

zanieb commented Oct 27, 2024

Then why are you worried about packages being removed? Sorry, I must be missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

2 participants