astral-sh / uv

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

uv doesn't detect pyenv-virtualenv shim environments #2109

Open jarshwah opened 5 months ago

jarshwah commented 5 months ago

uv doesn't seem able to detect the virtual-environment created by pyenv-virtualenv.

uv version and repro:

$ pyenv virtualenv 3.10.2 myenv
$ pyenv local myenv
$ which python
/Users/josh/.pyenv/shims/python

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

$ uv --version
uv 0.1.13 (9ce5170e6 2024-02-29)

$ python --version
Python 3.10.12

But it does detect the virtualenv when activating the shell:

$ pyenv activate kraken-uv
$ uv pip install pip==22.0.3
Resolved 1 package in 312ms
Downloaded 1 package in 168ms
Installed 1 package in 8ms
 - pip==23.0.1
 + pip==22.0.3
jarshwah commented 5 months ago

Workaround for those that are interested, using direnv:

if [ -f ".python-version" ] ; then
    envname=$(cat .python-version)
    VIRTUAL_ENV="$(pyenv root)/versions/$envname"
    export VIRTUAL_ENV
fi
NeilGirdhar commented 4 months ago

How about VIRTUAL_ENV="$(pyenv root)/versions/$(pyenv version-name)"?

zanieb commented 1 month ago

Would be closed by https://github.com/astral-sh/uv/pull/4032