astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
19.91k stars 586 forks source link

Sync with system Python? #5964

Closed b-phi closed 1 week ago

b-phi commented 1 month ago

I'm trying to use uv to synchronize environments across a cluster. This involves creating a lock file and then using it to install dependencies everywhere. As far as I can tell, uv sync only supports installing dependencies in a uv managed venv. Is there anyway to run sync against a target environment, the system Python in this case?

b-phi commented 1 month ago

I was able to workaround this by activating the environment dynamically, but this does feel like a bit of a hack since it doesn't guarantee that the environments are actually synced. This is with a dask cluster, I'm not aware of an easy way to "switch" to the new venv if the workers are started with the system python.

import runpy

runpy.run_path('.venv/bin/activate_this.py')
charliermarsh commented 1 month ago

Na this isn't supported yet.

chrisrodrigue commented 1 month ago

I think you can use uv venv --system-site-packages but uv sync is not yet aware of requirements that are already satisfied by the system/inherited environment so it still attempts to resolve and install them.

Samuel-Therrien-Beslogic commented 4 weeks ago

In the mean time, I'm addind the venv's bin (or Scripts on Windows) folder to PATH as per https://github.com/jakebailey/pyright-action/tree/v2/?tab=readme-ov-file#using-pyright-from-path :

jobs:
  mypy:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: canopeum_backend
    steps:
      - uses: actions/checkout@v4
      - name: Install uv using the standalone installer
        run: curl -LsSf https://astral.sh/uv/install.sh | sh
      - run: uv sync --locked --extra dev
      - run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
      - run: mypy . --python-version=3.12

  pyright:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: canopeum_backend
    steps:
      - uses: actions/checkout@v4
      - name: Install uv using the standalone installer
        run: curl -LsSf https://astral.sh/uv/install.sh | sh
      - run: uv sync --locked --extra dev
      - run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
      - uses: jakebailey/pyright-action@v2
        with:
          version: PATH
          python-version: "3.12"
          working-directory: canopeum_backend

And making sure that my docker commands are using uv run instead of python

seppzer0 commented 2 weeks ago

I upvote for the optional synchronization with the host system rather than with venv-only. Not only for CI/CD, but for me personally it is also occasionally preferable to install project packages into the system directly.

hauntsaninja commented 2 weeks ago

One option is to symlink:

ln -sf $(/path/to/target/python -c 'import sys; print(sys.prefix)') .venv 
uv sync
seppzer0 commented 1 week ago

I suppose it is a functional workaround, but having this implemented natively into uv would be a big improvement

zanieb commented 1 week ago

This is now supported via UV_PROJECT_ENVIRONMENT (#6834) — I still don't recommend it but you don't need to do a symlink.