简体   繁体   English

如何基于 yml 文件但使用不同的 Python 版本创建新的 conda env

[英]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.我有一个带有python=3.6.0的 conda 环境及其所有依赖项。 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.现在我想使用这个 yaml 文件来创建另一个具有相同依赖项但python=3.7.0环境,而不需要一个一个安装正确版本的包。

  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.在 YAML 的dependencies列表中应该有一个python条目,如果没有你可以添加一个。 Edit it to have the Python version you want.编辑它以获得所需的 Python 版本。

  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 .使用记事本将python替换为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. Conda 将尝试安装所有名称相同但版本不同的软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 windows 的 conda 中创建 env from.yml 文件? - How do i create env from .yml file in conda in windows? ResolvePackageNotFound:在 mac OSX 上使用 conda 和 yml 文件创建环境 - ResolvePackageNotFound: Create env using conda and yml file on mac OSX 如何从没有默认包的 yml 创建 conda env? - How do I create a conda env from a yml with no default packages? 如何使用更新的 Conda 创建新的 Conda 和 .yml 环境 - How to create new Conda and .yml environment with updated Conda 使用特定的 python 版本创建 conda env,并预先下载该 python 包 - create conda env with specific python version, with that python package predownloaded conda无法创建不同的Python版本环境 - Conda unable to create different Python version environment “SpecNotFound: Invalid name, try the format: user/package”在使用 yml 文件创建新的 Conda env (Windows 10) - "SpecNotFound: Invalid name, try the format: user/package" in Creating new Conda env with yml file (Windows 10) 如何使用'pip --user'方法'conda env create -f environment.yml' - How to 'conda env create -f environment.yml' using 'pip --user' method 如何在没有此错误的情况下使用 yml 文件创建 conda 环境? - How to create conda environment with yml file without this error? 无法从environment.yml创建conda env - Can't create conda env from environment.yml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM