Skip to content

Conversation

@akumor
Copy link
Contributor

@akumor akumor commented Oct 11, 2024

This adds the ability to install packages using %uv install [pkgs] line magic.

@akumor akumor force-pushed the add-uv-line-magic branch from 355cacc to 47ef0c1 Compare October 11, 2024 05:12
@akumor akumor marked this pull request as ready for review October 13, 2024 17:16
@akumor akumor force-pushed the add-uv-line-magic branch from 20a3581 to b0d61ed Compare October 13, 2024 17:19
@Carreau
Copy link
Member

Carreau commented Oct 16, 2024

I'm not sure this is worth it, what you are doing is basically transforming the %uv in !uv,
the case for pip/conda is that beginners tend to not differentiate CLI and Python prompt, and so we want to catch that and detect it.

I would suggest to make it as a package and if there is more interest and advantages over !uv we can bring it in, but I will need some convincing.

@dennisobrien
Copy link

I think the motivation here is that !uv install will usually do the wrong thing and install into a python environment other than the one running the current kernel. (In the same way that !pip install and !conda install will also do the wrong thing.) From this classic post from Jake VDP

in Jupyter, the shell environment and the Python executable are disconnected.

(I'm sure you know this much better than I do, I just want to include some motivation that is missing from the PR description.)

I can see the counter-argument here: should the ipython project be responsible for including magics for every python package/environment management module? That's definitely a question for the ipython maintainers. I don't know what the adoption rates for uv are, but our team has been really impressed with the speed and functionality. And it seems like uv is quickly getting traction.

@Carreau
Copy link
Member

Carreau commented Oct 16, 2024

I think the motivation here is that !uv install will usually do the wrong thing and install into a python environment other than the one running the current kernel.

Yes, but for pip I do take special care of actually calling sys.executable -m pip, while here you are using shutil.which, and if uv is not in current env, it will get the potentially system global, so this is identical to !uv, I guess least maybe do sys.executable -m uv (I think it should work, but I haven't use uv enough, especially the multi-env).

Unless I misunderstand how shutil.which works, or missed something else in the PR. (Which is honestly quite likely I'm just getting out of a few days sick and still brainfoggy).

@akumor
Copy link
Contributor Author

akumor commented Oct 17, 2024

Thank you for the feedback! I will work on updating the PR to use sys.executable -m uv. I knew you could install uv with pip but I did not realize python -m uv would work.

@Carreau
Copy link
Member

Carreau commented Oct 21, 2024

I'm still not 100% convinced it is needed, but let's try it.

@Carreau Carreau merged commit 02545e9 into ipython:main Oct 21, 2024
@Carreau
Copy link
Member

Carreau commented Oct 21, 2024

Thanks.

@wimglenn
Copy link
Contributor

wimglenn commented Oct 25, 2024

Err, this requires uv to have been installed to the Python env, which is not the usual uv installation method. Usually it is installed directly or with cargo, their executable autodetects a .venv presence, and there is no Python package in-env.

With a normal uv installation, if you try to use this magic, you'll currently get something like:

>>> %uv install urllib3
/tmp/example/.venv/bin/python: No module named uv
Note: you may need to restart the kernel to use updated packages.

A more correct approach would be to make the magic use uv pip install --python <sys.executable> ...

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 this pull request may close these issues.

4 participants