Skip to content

Commit 02545e9

Browse files
authored
Add uv line magic (ipython#14537)
This adds the ability to install packages using `%uv install [pkgs]` line magic.
2 parents 1451544 + bf9303a commit 02545e9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

IPython/core/magics/packaging.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,20 @@ def micromamba(self, line):
162162
"""
163163
micromamba = _get_conda_like_executable("micromamba")
164164
self._run_command(micromamba, line)
165+
166+
@line_magic
167+
def uv(self, line):
168+
"""Run the uv package manager within the current kernel.
169+
170+
Usage:
171+
%uv pip install [pkgs]
172+
"""
173+
python = sys.executable
174+
if sys.platform == "win32":
175+
python = '"' + python + '"'
176+
else:
177+
python = shlex.quote(python)
178+
179+
self.shell.system(" ".join([python, "-m", "uv", line]))
180+
181+
print("Note: you may need to restart the kernel to use updated packages.")

0 commit comments

Comments
 (0)