Skip to content
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

Fix path handling in pip line magic #13052

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion IPython/core/magics/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@

import re
import shlex
import subprocess
import sys
from pathlib import Path

from IPython.core.magic import Magics, magics_class, line_magic


def _format_command(*args):
"""Use subprocess.list2cmdline to quote and escape executable path"""
return subprocess.list2cmdline(list(args))


def _is_conda_environment():
"""Return True if the current Python executable is in a conda env"""
# TODO: does this need to change on windows?
Expand Down Expand Up @@ -66,7 +72,11 @@ def pip(self, line):
Usage:
%pip install [pkgs]
"""
self.shell.system(' '.join([sys.executable, '-m', 'pip', line]))
python = sys.executable
args = shlex.split(line)
command = _format_command(python, "-m", "pip", *args)
MrMino marked this conversation as resolved.
Show resolved Hide resolved

self.shell.system(command)
print("Note: you may need to restart the kernel to use updated packages.")

@line_magic
Expand Down