如何从一个Python版本到另一个Python版本克隆一个conda环境? [英] How do I clone a conda environment from one python release to another?

查看:360
本文介绍了如何从一个Python版本到另一个Python版本克隆一个conda环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python 2.7 conda环境,并且想用python 3.4创建一个等效的环境。我知道在创建环境时使用-clone 选项,但是它不接受其他参数,例如 python = 3.4 。有没有一种方法可以自动执行此操作?我考虑过尝试使用 conda list --export 的输出,但这也对python版本进行了编码。

I have a python 2.7 conda environment and would like to create an equivalent environment with python 3.4. I am aware of the --clone option when creating environments, but it won't accept additional arguments, like python=3.4. Is there a way to do this automatically? I thought about trying to use the output from conda list --export, but that also encodes the python release.

推荐答案

一种方法是

conda list --export > exported-packages.txt

然后编辑该文件,以<删除每个软件包的最后一部分code> py27_0 部分(如果某些版本的软件包没有Python 3版本,您可能还想删除这些版本)。然后

And then edit that file to remove the last part of each package with the py27_0 parts (you might also want to remove the versions, in case some version of a package doesn't have a Python 3 version). Then

conda create -n py3clone --file exported-packages.txt

另一个想法是克隆环境:

Another idea would be to clone the environment:

conda create -n clonedenv --clone oldenv
conda install -n clonedenv python=3.4
conda update -n clonedenv --all

请注意,如果您使用的某些软件包没有Python 3版本,则显然这两种方法都会失败。

Note that obviously both of these will fail if you have some package that doesn't have a Python 3 version.

这篇关于如何从一个Python版本到另一个Python版本克隆一个conda环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆