TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/conda/conda/llms.txt
Use this file to discover all available pages before exploring further.
conda compare command compares the packages installed in a conda environment with the packages specified in an environment file. This is useful for verifying that an environment matches its specification.
Syntax
Arguments
FILE
Path to the environment file that is to be compared against. Can be a local file path or a URL.
Options
-n, --name NAME
Name of the environment to compare.
-p, --prefix PREFIX
Full path to the environment prefix to compare.
--json
Report all output as JSON. Suitable for programmatic use.
Output
The command returns:- Exit code 0: All packages in the specification file are present in the environment with matching version and build string
- Exit code 1: One or more packages are missing or have mismatched versions
Success Output
Error Output
When packages don’t match, the output shows:- Missing packages:
<package_name> not found - Mismatched packages:
<package_name> found but mismatch. Specification pkg: <spec>, Running pkg: <installed>
Common Use Cases
Compare current environment with specification
Compare packages in the current environment with an environment.yml file:Compare named environment with specification
Compare a specific environment:Compare environment with remote specification
Fetch and compare against a remote environment file:Use in CI/CD pipelines
Verify that an environment matches its specification:Get JSON output for automation
How It Works
Theconda compare command:
- Reads the environment file (supports various formats via plugins)
- Extracts the list of requested packages from the specification
- Gets the list of installed packages in the target environment
- Compares each package from the specification against installed packages
- Checks that:
- The package exists in the environment
- The version matches the specification (if specified)
- The build string matches (if specified)
The comparison uses conda’s MatchSpec system, which supports flexible version specifications like
>=1.0, 1.*, etc.Environment File Formats
The command supports different environment file formats through conda’s plugin system, including:environment.yml(conda format)requirements.txt(pip format)- Other formats via installed plugins
Example: Complete Workflow
Create environment from file
Verify environment matches specification
Handle mismatches
Use Cases
- CI/CD validation: Ensure environments in production match specifications
- Debugging: Identify package version mismatches
- Documentation: Verify environment documentation is up-to-date
- Reproducibility: Confirm environments can be reproduced from files
- Compliance: Check that environments meet specific requirements