LinuxCommandLibrary

conda-run

Run command in conda environment

TLDR

Run a command in the currently active environment

$ conda run [command]
copy

Target an environment by name
$ conda run [[-n|--name]] [environment_name] [command]
copy

Target an environment by its path (i.e. prefix)
$ conda run [[-p|--prefix]] [path/to/env] [command]
copy

SYNOPSIS

conda run [options] [-n ENVIRONMENT | -p PATH] [COMMAND] [ARGS …]

PARAMETERS

-h, --help
    Show help message and exit.

--debug
    Display verbose debug information.

--verify
    Verify requested package versions are installed before running.

--no-capture-output
    Do not capture stdout/stderr; requires --live-stream.

--live-stream
    Stream command output in real-time without buffering.

-n, --name ENVIRONMENT
    Name of the Conda environment to use.

-p, --prefix PATH
    Full path to the environment directory.

-s, --no-builds
    Ignore build strings in environment variables for faster builds.

--cwd CWD
    Set working directory for the command.

--env-var ENVVAR
    Set custom environment variable.

--no-env-var NO_ENVVAR
    Unset specified environment variable.

DESCRIPTION

The conda run command executes a specified program within a particular Conda environment without activating it in the current shell. This avoids modifying the shell's PATH and other environment variables persistently, making it ideal for scripts, CI/CD pipelines, and non-interactive use cases.

Unlike conda activate, which changes the current session, conda run spawns a subprocess with the environment loaded temporarily. It sets up the environment variables like CONDA_PREFIX, PATH, and others as if activated, runs the command, and then exits, leaving the parent shell unchanged.

This is particularly useful in automation where activation might fail or cause side effects, such as in Docker containers or batch jobs. It supports both named environments (-n) and path-based prefixes (-p), and offers options for output handling, working directory, and custom environment variables.

CAVEATS

Requires Conda 4.6+; command must exist in the target environment; --live-stream incompatible with capture modes; not for interactive shells preferring activation.

EXAMPLES

conda run -n myenv python -c 'print(__file__)'
Runs Python code in 'myenv' environment.

conda run -p /path/to/env pip install pkg
Installs package using prefix path.

conda run --live-stream --cwd /tmp -n testenv ./script.sh
Streams output from script in custom directory.

HISTORY

Introduced in Conda 4.6.0 (2018) to solve activation issues in scripts and non-interactive contexts, evolving from community requests for subprocess execution without shell modification.

SEE ALSO

conda(1), bash(1), env(1)

Copied to clipboard