anaconda

How to reliably copy anaconda/mamba envs when --clone fails?


I'm trying to create a sandbox copy of an existing environment for package experimentation. But I've found that both conda create env --clone and conda env export + conda env create -f fail... Are there workarounds for this?

Like for example can I copy/paste the environment directory and rename it or something? Or perhaps tell conda to get it's packages from the existing environment rather than reinstalling them?

P.S. Clone tends to give an error like:

PackagesNotFoundError: The following packages are missing from the target environment:
  - pandas==2.2.1=pypi_0
 ...

And Import/Export gives an error like:

Pip subprocess error:
ERROR: Ignored the following versions that require a different python version: 0.13.0 Requires-Python >=3.10; 0.13.1 Requires-Python >=3.10; 0.14.0 Requires-Python >=3.11; ...
ERROR: Could not find a version that satisfies the requirement python-graphviz==0.20.3 (from versions: none)
ERROR: No matching distribution found for python-graphviz==0.20.3

Solution

  • You could try conda pack for that. It was designed to ship environments to another system reliably. But since you can rename the env arbitrarily while unpacking, there is nothing stopping you from packing and unpacking on the same system and renaming in the process

    #While conda base is activated
    conda install -c conda-forge conda-pack
    conda pack -n <name of env you want to clone> #creates a packedEnv.tar.gz named after old env
    mkdir /path/to/conda/env/location/envs/<newEnvName>
    tar -xvf <packedEnv.tar.gz> -C /path/to/conda/env/location/envs/<newEnvName>
    source /path/to/conda/env/location/envs/<newEnvName>/bin/activate
    conda unpack
    

    The new env should appear with the name in conda list now