conda-run
Run command in conda environment
TLDR
Run a command in the currently active environment
Target an environment by name
Target an environment by its path (i.e. prefix)
SYNOPSIS
conda-run [OPTIONS] COMMAND [ARGUMENTS...]
PARAMETERS
--name <environment>, -n <environment>
Name of the conda environment to run the command in.
--prefix <path>, -p <path>
Full path to the conda environment to run the command in.
--cwd <path>
Working directory to run the command in. Defaults to the current directory.
--env <VAR=VALUE>
Set environment variables for the executed command. Can be specified multiple times for different variables.
--no-default-packages
Do not include default packages (e.g., Python, pip, setuptools, wheel) in the environment setup. This is rarely needed for typical use.
--debug
Show debug messages for detailed execution information.
--json
Report all output as a JSON object. Useful for programmatic parsing and automation.
--help, -h
Show a help message for conda-run and exit.
--verbose, -v
Use verbose output, showing more details during execution.
--quiet, -q
Do not display progress bar or other informational messages.
DESCRIPTION
conda-run allows executing a command within a designated conda environment without the need to explicitly activate it first. This command is particularly useful for scripting, automation, and non-interactive workflows where changing the current shell's state is undesirable.
It sets up the specified environment's paths and variables for the duration of the command's execution, ensuring that the command runs with the correct dependencies and versions. Unlike conda activate, which modifies the current shell session, conda-run creates a temporary execution context, providing a clean and isolated way to interact with different conda environments. This greatly simplifies tasks like running a Python script with a specific Python version or executing tools installed in a particular environment without affecting the calling shell.
CAVEATS
conda-run does not perform a full environment activation in the same way conda activate does. It primarily modifies the `PATH` and sets essential environment variables for the command's execution. Therefore, some shell-specific configurations or scripts that rely on a full activation (e.g., sourcing custom `activate.d` scripts) might not behave as expected. It also requires conda to be initialized in the shell where it's executed, otherwise, the `conda` command itself won't be found.
EXECUTION CONTEXT
When invoked, conda-run constructs a new, temporary execution environment. Within this context, the specified conda environment's binaries are prioritized in the `PATH`, and relevant environment variables (like `CONDA_PREFIX`, `CONDA_DEFAULT_ENV`) are set. This temporary isolation ensures the command finds the correct versions of executables and libraries without permanently changing the shell from which conda-run was called, promoting reproducibility and avoiding conflicts.
RETURN CODE
The exit code of conda-run will be the exit code of the COMMAND it executes. This behavior allows for standard error checking and conditional logic in scripts, making it robust for automation workflows.
HISTORY
The Conda project, initiated by Anaconda, Inc., has continuously evolved to provide robust cross-platform package and environment management. conda-run was introduced as a utility to enhance scripting capabilities and facilitate non-interactive execution of commands within specific Conda environments. It addressed a common need for cleaner automation workflows, especially in continuous integration/continuous deployment (CI/CD) pipelines and complex scripting tasks, by offering a way to utilize Conda environments without altering the user's interactive shell state.


