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

Adr*_*ian 6 python environment yaml version conda

我有一个 conda 环境及其python=3.6.0所有依赖项。现在我想使用这个 yaml 文件创建另一个具有相同依赖项的环境,但不需要python=3.7.0一一安装具有正确版本的包。

mer*_*erv 6

  1. 导出环境的最小版本:

    conda env export -n old_env --from-history > env.yaml
    
    Run Code Online (Sandbox Code Playgroud)
  2. dependenciesYAML 列表中应该有一个python条目,如果没有,您可以添加一个条目。编辑它以获得您想要的 Python 版本。

  3. 创建新环境:

    conda env create -n new_env -f env.yaml
    
    Run Code Online (Sandbox Code Playgroud)


Cra*_*cle 1

# 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

Run Code Online (Sandbox Code Playgroud)

使用记事本替换pythonpython==3.7. 然后使用编辑后的包列表创建一个新环境。

conda create --name so2
conda activate so2
conda install _libgcc_mutex ... python==3.7 ... zstd
Run Code Online (Sandbox Code Playgroud)

Conda 将尝试安装所有具有相同名称但不同版本的软件包。