LinuxCommandLibrary

conda-export

Export Conda environment specifications

TLDR

Export the current environment details to stdout

$ conda export
copy

Export the current environment details to a YAML file
$ conda export [[-f|--file]] [path/to/environment.yaml]
copy

Export details in a specific format
$ conda export --format [environment-json|environment-yaml|explicit|json|reqs|requirements|txt|yaml|yml]
copy

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

Target an environment by its path
$ conda export [[-p|--prefix]] [path/to/environment]
copy

Include a specific channel
$ conda export [[-c|--channel]] [channel_name]
copy

SYNOPSIS

conda env export [-h] [--no-builds] [--override-channels] [-c CHANNEL] [--from-history] [-n ENVIRONMENT | -p PATH] [-f FILE]

PARAMETERS

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

--no-builds
    Remove build specifications from the exported dependencies. This makes the environment file more platform-agnostic but potentially less reproducible if specific build versions are critical.

--override-channels
    Include explicit channel URLs that override the default channels. These will be prepended to the environment definition, ensuring packages are sought from specified sources first.

-c CHANNEL, --channel CHANNEL
    Specify an additional channel to include in the export. This option can be used multiple times to add several channels.

--from-history
    Export only the packages that were explicitly requested when the environment was initially created, rather than all currently installed packages. This results in a cleaner, often smaller environment file.

-n ENVIRONMENT, --name ENVIRONMENT
    Specify the name of the Conda environment to export. If omitted, the currently active environment is used.

-p PATH, --prefix PATH
    Specify the full path to the Conda environment prefix to export. This is an alternative to specifying the environment by name.

-f FILE, --file FILE
    Write the exported environment definition to the specified file. If this option is not provided, the output is written to standard output (stdout).

DESCRIPTION

The conda env export command is a crucial tool within the Conda ecosystem, designed to capture and share the exact configuration of a Conda environment. It generates a YAML file (typically named environment.yml) that lists all installed packages, their versions, and the channels from which they originated. This file serves as a blueprint, enabling users to precisely recreate the same environment on different machines or at a later time, ensuring project reproducibility.

This command is invaluable for collaboration, version control of environments, and deploying applications consistently across various systems. By default, it exports all packages present in the active or specified environment. However, options like --from-history allow for exporting only those packages explicitly requested during the environment's creation, leading to a more concise and potentially more portable environment definition. The generated YAML file can then be used with conda env create -f environment.yml or conda env update -f environment.yml to replicate the environment.

CAVEATS

When exporting environments, be aware that without --no-builds, the generated YAML file will include platform-specific build strings, potentially hindering cross-platform reproducibility. Channel order is also crucial; the order in which channels are listed in the YAML file dictates the package resolution priority. Using --from-history is often preferred for sharing minimal, reproducible environments, but it might not capture all dependencies if additional packages were installed implicitly.

BEST PRACTICES FOR ENVIRONMENT SHARING

For maximum portability and minimal file size, it's often recommended to use conda env export --from-history --no-builds -f environment.yml. This creates a more abstract definition that prioritizes package names and versions over specific build artifacts and transient dependencies, making it easier to recreate on different operating systems and architectures. Always include the generated environment.yml file in your project's version control system (e.g., Git) to track environment changes alongside your code.

HISTORY

The conda env export command is part of the broader Conda project, which was developed by Continuum Analytics (now Anaconda, Inc.) to address the challenges of package, dependency, and environment management, particularly in scientific computing. As data science and machine learning workflows became more complex, ensuring reproducible computational environments became paramount. This led to the introduction and continuous refinement of `conda env` subcommands, with `export` being a cornerstone for defining and sharing these environments in a standardized, human-readable YAML format.

SEE ALSO

conda(1), conda-create(1), conda-env-update(1), conda-list(1), pip-freeze(1)

Copied to clipboard