-
Notifications
You must be signed in to change notification settings - Fork 615
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
Automatically detect virtual environments when used via python -m uv
#1504
Conversation
cc @altendky :) |
python/uv/__main__.py
Outdated
return value | ||
|
||
# Otherwise, check if we're in a venv | ||
maybe_venv_dir = os.path.dirname(os.path.dirname(sys.executable)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be something like (Path(sys.prefix) / "pyvenv.cfg").exists()
(probably without the pathlib for speed, but I'm lazy here)? This assumes that there is exactly one level between the bin
or Scripts
dir and the base prefix, which I don't think is guaranteed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I thought what I was doing might be brittle.. let me look into that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/library/sysconfig.html#installation-paths Looks like you can sometimes get a posix_prefix
. Might lead to more details about 'correctness' as well.
Thanks! $ python3.11 -m venv venv $ venv/bin/python -m pip install 'uv @ git+https://github.com/astral-sh/uv@1ed6ba0ba0d3756312085ec21c90469985b5bbb6'
Collecting uv@ git+https://github.com/astral-sh/uv@1ed6ba0ba0d3756312085ec21c90469985b5bbb6
Using cached uv-0.1.2-py3-none-linux_x86_64.whl
Installing collected packages: uv
Successfully installed uv-0.1.2
[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: /home/altendky/tmp/venv/bin/python -m pip install --upgrade pip Installed $ venv/bin/python -m uv pip install attrs
error: Failed to locate a virtualenv or Conda environment (checked: `VIRTUAL_ENV`, `CONDA_PREFIX`, and `.venv`). Run `uv venv` to create a virtualenv. $ venv/bin/python -m pip install 'uv @ git+https://github.com/astral-sh/uv@967188a914df3461b92de27e9b9234fd8c22be85'
Collecting uv@ git+https://github.com/astral-sh/uv@967188a914df3461b92de27e9b9234fd8c22be85
Using cached uv-0.1.1-py3-none-linux_x86_64.whl
Installing collected packages: uv
Attempting uninstall: uv
Found existing installation: uv 0.1.2
Uninstalling uv-0.1.2:
Successfully uninstalled uv-0.1.2
Successfully installed uv-0.1.1
[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: /home/altendky/tmp/venv/bin/python -m pip install --upgrade pip Installed this PR above and see it succeeding below. $ venv/bin/python -m uv pip install attrs
Resolved 1 package in 107ms
Installed 1 package in 9ms
+ attrs==23.2.0 |
…#1667) From #1623 (comment) I thought I checked this was working correctly in #1504 but I guess the environment is not preserved like I thought.
Closes #1501