From 02545e95585fa222f9e83b83161e6af4065fd6f7 2024-10-21 06:41:33 From: M Bussonnier Date: 2024-10-21 06:41:33 Subject: [PATCH] Add uv line magic (#14537) This adds the ability to install packages using `%uv install [pkgs]` line magic. --- diff --git a/IPython/core/magics/packaging.py b/IPython/core/magics/packaging.py index 09d4117..ed1c127 100644 --- a/IPython/core/magics/packaging.py +++ b/IPython/core/magics/packaging.py @@ -162,3 +162,20 @@ class PackagingMagics(Magics): """ micromamba = _get_conda_like_executable("micromamba") self._run_command(micromamba, line) + + @line_magic + def uv(self, line): + """Run the uv package manager within the current kernel. + + Usage: + %uv pip install [pkgs] + """ + python = sys.executable + if sys.platform == "win32": + python = '"' + python + '"' + else: + python = shlex.quote(python) + + self.shell.system(" ".join([python, "-m", "uv", line])) + + print("Note: you may need to restart the kernel to use updated packages.")