Search code examples
pythonyamlversioncondaenvironment

How to create a new conda env based on a yml file but with different Python version


I have a conda environment with python=3.6.0 and all it's dependencies. Now I would like to use this yaml file to create another environment with the same dependencies but with python=3.7.0 without the need for installing the packages with right version one by one.


Solution

  • # Activate old environment
    conda activate so
    # Save the list of package to a file:
    conda list > log
    # Extract the package name but not the version or hash
    cat log | awk '{print $1}' > log2
    # make the list of packages
    tr '\n' ' ' < log2 > log3
    # print the list of packages
    cat log3
    
    

    Use notepad to replace python by python==3.7. Then create a new environment with the edited list of packages.

    conda create --name so2
    conda activate so2
    conda install _libgcc_mutex ... python==3.7 ... zstd
    

    Conda will try to install all packages with the same name but different version.