Adrian
Adrian

Reputation: 213

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.

Upvotes: 6

Views: 8304

Answers (2)

merv
merv

Reputation: 76810

  1. Export a minimal version of the environment:

    conda env export -n old_env --from-history > env.yaml
    
  2. In the dependencies list of the YAML there should be a python entry, if not you can add one. Edit it to have the Python version you want.

  3. Create the new environment:

    conda env create -n new_env -f env.yaml
    

Upvotes: 6

Crawl Cycle
Crawl Cycle

Reputation: 287

# 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.

Upvotes: 1

Related Questions