conda.cli.python_api

class conda.cli.python_api.Commands
CLEAN = 'clean'
CONFIG = 'config'
CREATE = 'create'
HELP = 'help'
INFO = 'info'
INSTALL = 'install'
LIST = 'list'
REMOVE = 'remove'
RUN = 'run'
SEARCH = 'search'
UPDATE = 'update'
conda.cli.python_api.run_command(command, *arguments, **kwargs)

Runs a conda command in-process with a given set of command-line interface arguments.

Differences from the command-line interface:

Always uses --yes flag, thus does not ask for confirmation.

Parameters
  • command -- one of the Commands.

  • *arguments -- instructions you would normally pass to the conda comamnd on the command line see below for examples. Be very careful to delimit arguements exactly as you want them to be delivered. No 'combine then split at spaces' or other information destroying processing gets performed on the arguments.

  • **kwargs -- special instructions for programmatic overrides

Keyword Arguments
  • use_exception_handler -- defaults to False. False will let the code calling run_command handle all exceptions. True won't raise when an exception has occured, and instead give a non-zero return code

  • search_path -- an optional non-standard search path for configuration information that overrides the default SEARCH_PATH

  • stdout -- Define capture behavior for stream sys.stdout. Defaults to STRING. STRING captures as a string. None leaves stream untouched. Otherwise redirect to file-like object stdout.

  • stderr -- Define capture behavior for stream sys.stderr. Defaults to STRING. STRING captures as a string. None leaves stream untouched. STDOUT redirects to stdout target and returns None as stderr value. Otherwise redirect to file-like object stderr.

Returns: a tuple of stdout, stderr, and return_code.

stdout, stderr are either strings, None or the corresponding file-like function argument.

Examples

>> run_command(Commands.CREATE, "-n", "newenv", "python=3", "flask", use_exception_handler=True) >> run_command(Commands.CREATE, "-n", "newenv", "python=3", "flask") >> run_command(Commands.CREATE, ["-n", "newenv", "python=3", "flask"], search_path=())