uv icon indicating copy to clipboard operation
uv copied to clipboard

Include `bin/uv` in `uv venv`

Open gotmax23 opened this issue 1 year ago • 7 comments

  • A minimal code snippet that reproduces the bug.

    $ uv venv venv
    $ ./venv/bin/uv install ipython
    no such file or directory: ./venv/bin/uv
    
  • The current uv platform.

    Fedora 40 with Python 3.12

  • The current uv version (uv --version).

    0.2.35

It would be great if a uv binary was included in virtual environments' bin directories so it would be possible to install packages inside using uv without having to activate the venv, similar to how standard virtual environments' pip entrypoints work.

gotmax23 avatar Aug 19 '24 23:08 gotmax23

You can pass --python .venv to install into that environment -- uv doesn't need to be installed inside it.

charliermarsh avatar Aug 19 '24 23:08 charliermarsh

e.g.

❯ uv venv venv
Using Python 3.12.1
Creating virtualenv at: venv
Activate with: source venv/bin/activate
❯ uv pip install httpx --python ./venv
Resolved 7 packages in 207ms
Installed 7 packages in 17ms
 + anyio==4.4.0
 + certifi==2024.7.4
 + h11==0.14.0
 + httpcore==1.0.5
 + httpx==0.27.0
 + idna==3.7
 + sniffio==1.3.1

or

❯ VIRTUAL_ENV=venv uv pip install httpx
Audited 1 package in 4ms

zanieb avatar Aug 20 '24 00:08 zanieb

I didn't know that --python could be used like this; thanks. I guess I'm just really used to invoking pip like this in scripts, but I could always adapt...

gotmax23 avatar Aug 20 '24 19:08 gotmax23

This sort of relates to the --seed option although it's kind of obscure (and a compatibility shim?) I suppose. Its existence probably steers people from discovering the --python pattern -- it took me some time before I had the same a-ha moment.

paveldikov avatar Aug 20 '24 23:08 paveldikov

This sort of relates to the --seed option although it's kind of obscure (and a compatibility shim?) I suppose. Its existence probably steers people from discovering the --python pattern -- it took me some time before I had the same a-ha moment.

Same here.

❯ uv venv venv
Using Python 3.12.1
Creating virtualenv at: venv
Activate with: source venv/bin/activate
❯ uv pip install httpx --python ./venv

Is this trick not included in the docs for any specific reason?

nixshal avatar Aug 22 '24 06:08 nixshal

It's sort of mentioned in https://docs.astral.sh/uv/concepts/python-versions/#requesting-a-version — we could add a note where you linked but it's not mentioned there because that section is about using the packages in the environment — not installing things into it. I can look into clarifying it though.

zanieb avatar Aug 22 '24 15:08 zanieb

Thank you @zanieb .

I do think the mistake is on my side, I was using uv by invoking uv via Python (using the parent interpreter's environment).

Installing uv via the standalone installer fixed my issues here and I was able to follow the docs; turns out it was a powershell elevated access setting I needed to fix in order to get the standalone installer working.

nixshal avatar Aug 23 '24 01:08 nixshal