简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM