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

Confused about how to use without a virtualenv #124

Closed
ngoldbaum opened this issue Oct 17, 2024 · 8 comments · Fixed by #194
Closed

Confused about how to use without a virtualenv #124

ngoldbaum opened this issue Oct 17, 2024 · 8 comments · Fixed by #194

Comments

@ngoldbaum
Copy link

ngoldbaum commented Oct 17, 2024

I feel like I'm going against the grain here and maybe that's the issue.

I'd like to replace setup-python with setup-uv. Our existing CI uses python from setup-python directly, without setting up a virtualenv.

Is it possible to use uv in a similar way? Basically, I'd like to install directly into the global environment associated with a uv python install command. When I try to actually do that, I see errors like:

Run uv pip install --python=3.13t -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython
  
error: No virtual environment found for Python 3.13t; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment

Is the right thing to do here to put uv's python at the front of the PATH and then pass --system? Or just use a virtualenv? If it's the latter, then this is not quite a drop-in replacement for setup-python, since that's not necessary with setup-python.

@ngoldbaum
Copy link
Author

And if I put the path to the uv-managed python at the front of my PATH environment variable, and then try to install something into its environment with uv pip install --system, I get errors like:

  error: The interpreter at /home/runner/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu is externally managed, and indicates the following:
  
    This Python installation is managed by uv and should not be modified.
  
  Consider creating a virtual environment with `uv venv`.

@ngoldbaum
Copy link
Author

The way I've worked around this is by activating the virtualenv once, then inserting the updated PATH into GITHUB_ENV:

    - uses: astral-sh/setup-uv@f3bcaebff5eace81a1c062af9f9011aae482ca9d
    - run: |
        uv python install 3.13t
        uv venv --python 3.13t
        uv pip install pip
        . .venv/bin/activate
        echo PATH=$PATH >> $GITHUB_ENV

It looks like the setup-pixi action has an activate-envrionment option that does the same thing with a bit nicer of UX. Might it make sense for setup-uv to do add a similar feature?

@eifinger
Copy link
Collaborator

eifinger commented Oct 25, 2024

Could you please add a bit of context on the bigger picture and what you are trying to achieve?

My understanding is, that you want to use uv to install packages into your system (faster than with pip) to then use those packages without a venv. Is that correct?
EDIT: Saw the linked issue in numpy. I also tried a bit around and got to the same conclusions as you so far. Will keep you posted

@ngoldbaum
Copy link
Author

Ah, great, glad you were ultimately able to figure out what I meant.

@mscheltienne
Copy link

I agree it's a bit confusing, at the moment I'm going with:

      - name: Setup Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install uv
        uses: astral-sh/setup-uv@v3
      - name: Install package
        run: uv pip install --quiet --system .[test]

But it doesn't seems like the recommended approach.

@eifinger
Copy link
Collaborator

eifinger commented Dec 16, 2024

@ngoldbaum it took me some time to come around to your issue. I saw you already closed your PR in numpy.

Could you still please verify if the following fits your expected behavior? (note the branch name as a version specifier)

- name: Install uv
  uses: astral-sh/setup-uv@auto-environment
  with:
    python-version: 3.13t
- run: uv pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython

@agriyakhetarpal I saw you mention also having problems in your linked pyodide issue. I would appreciate your feedback to the above.

Relevant PR: #194

@ngoldbaum
Copy link
Author

Thanks! I'll try to look at this soon but am on PTO until the new year so might not get to it until 2025.

@agriyakhetarpal
Copy link

Could you still please verify if the following fits your expected behavior? (note the branch name as a version specifier)

- name: Install uv
  uses: astral-sh/setup-uv@auto-environment
  with:
    python-version: 3.13t
- run: uv pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython

@agriyakhetarpal I saw you mention also having problems in your linked pyodide issue. I would appreciate your feedback to the above.

Relevant PR: #194

Hi @eifinger, this looks perfect to me! Also, it is in line with the activate-environment: input available in other actions in the ecosystem such as setup-miniconda, good note on the naming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants