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

Cannot uv pip install without virtualenv #1374

Closed
hauntsaninja opened this issue Feb 15, 2024 · 8 comments
Closed

Cannot uv pip install without virtualenv #1374

hauntsaninja opened this issue Feb 15, 2024 · 8 comments
Labels
enhancement New feature or request

Comments

@hauntsaninja
Copy link
Contributor

hauntsaninja commented Feb 15, 2024

It's common to not use virtual environments in containers, e.g. see discussion around PEP 704. I don't mind the default being to prevent installation into a base environment, but it would be nice to have some low level flag to override it.

error: Failed to locate a virtualenv or Conda environment (checked: `VIRTUAL_ENV`, `CONDA_PREFIX`, and `.venv`). Run `uv venv` to create a virtualenv.

(Maybe I can lie about VIRTUAL_ENV to work around...)

@hauntsaninja hauntsaninja changed the title Cannot uv pip install in container without virtualenv Cannot uv pip install without virtualenv Feb 15, 2024
@charliermarsh
Copy link
Member

👍 Agreed, we need some solution to this. I believe setting VIRTUAL_ENV would work, but it should be a first-class feature.

@batazor
Copy link

batazor commented Feb 16, 2024

It would also be cool to do a couple of examples on how to create a Dockerfile

especially with multi-stage builds, as I don't want to carry all the dependencies (c-library) that are needed when building, previously I used --wheel-dir /app/wheels to do this

@dmwyatt
Copy link

dmwyatt commented Feb 17, 2024

Here's how I setup my Dockerfile to work until we get a feature in uv to specifically support this:

ENV VIRTUAL_ENV /usr/local/

RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
    && . $HOME/.cargo/env \
    && uv pip compile requirements.in -o requirements.txt \
    && uv pip sync requirements.txt

/usr/local/ is correct on slim-bullseye images, you'll have to modify for whatever you image uses.

@hauntsaninja
Copy link
Contributor Author

Since this issue is somewhat popular, just noting that I've been doing VIRTUAL_ENV=$(python -c "import sys; print(sys.prefix)") uv pip ...

vladsavelyev added a commit to MultiQC/MultiQC that referenced this issue Feb 18, 2024
@ofek
Copy link
Contributor

ofek commented Feb 18, 2024

This probably would be the ultimate fix #1396

@ericbn
Copy link

ericbn commented Feb 19, 2024

pip has the --require-virtualenv option which makes it behave like uv:

$ pip install --require-virtualenv attrs
ERROR: Could not find an activated virtualenv (required).

but --no-require-virtualenv seems too long of a name for an option in uv. And sure the default uv behavior is much saner default!

@zanieb
Copy link
Member

zanieb commented Feb 19, 2024

I think we can track this in #1396 and #1526 since those are concrete solutions.

Thanks everyone!

@zanieb zanieb closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 2024
vladsavelyev added a commit to MultiQC/MultiQC that referenced this issue Apr 22, 2024
* CI: use uv pip

* [automated] Update CHANGELOG.md

* Try setting VIRTUAL_ENV (astral-sh/uv#1374)

* Set up VIRTUAL_ENV in a separate stage astral-sh/uv#1526

* No need to install pip and setuptools, no need BeautifulSoup for Windows (only CSP)

* Replace setup.py with pyproject.toml

* Need -e to install .

* Hack to get around duplicated pip package issue

* No need for BS in Windows

* Set VIRTUAL_ENV on Win

* Fix

* uv has bugs on windows?

* [automated] Update CHANGELOG.md

* Update and remove hacks

* Fix for windows

* No uv for windows

---------

Co-authored-by: MultiQC Bot <multiqc-bot@seqera.io>
@SzilvasiPeter
Copy link

I will mention the simplest solution, the --system option since other comments do not mention it. Also, the documentation highlights this option for containerized environments:

uv pip install --system

WARNING: --system is intended for use in continuous integration (CI) environments and should be used with caution, as it can modify the system Python installation.

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

No branches or pull requests

8 participants