MCPcopy Create free account
hub / github.com/ipython/ipython / conda

Method conda

IPython/core/magics/packaging.py:72–103  ·  view source on GitHub ↗

Run the conda package manager within the current kernel. Usage: %conda install [pkgs]

(self, line)

Source from the content-addressed store, hash-verified

70
71 @line_magic
72 def conda(self, line):
73 """Run the conda package manager within the current kernel.
74
75 Usage:
76 %conda install [pkgs]
77 """
78 if not _is_conda_environment():
79 raise ValueError("The python kernel does not appear to be a conda environment. "
80 "Please use ``%pip install`` instead.")
81
82 conda = _get_conda_executable()
83 args = shlex.split(line)
84 command = args[0]
85 args = args[1:]
86 extra_args = []
87
88 # When the subprocess does not allow us to respond "yes" during the installation,
89 # we need to insert --yes in the argument list for some commands
90 stdin_disabled = getattr(self.shell, 'kernel', None) is not None
91 needs_yes = command in CONDA_COMMANDS_REQUIRING_YES
92 has_yes = set(args).intersection(CONDA_YES_FLAGS)
93 if stdin_disabled and needs_yes and not has_yes:
94 extra_args.append("--yes")
95
96 # Add --prefix to point conda installation to the current environment
97 needs_prefix = command in CONDA_COMMANDS_REQUIRING_PREFIX
98 has_prefix = set(args).intersection(CONDA_ENV_FLAGS)
99 if needs_prefix and not has_prefix:
100 extra_args.extend(["--prefix", sys.prefix])
101
102 self.shell.system(' '.join([conda, command] + extra_args + args))
103 print("\nNote: you may need to restart the kernel to use updated packages.")

Callers

nothing calls this directly

Calls 3

_is_conda_environmentFunction · 0.85
_get_conda_executableFunction · 0.85
systemMethod · 0.80

Tested by

no test coverage detected