How do I clone a conda environment from one python release to another?

Question:

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.

Asked By: godber

||

Answers:

One way would be to

conda list --export > exported-packages.txt

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

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

Answered By: asmeurer

I tried this and had a lot of issues with plot.ly being updated to v. 4. My code was written on 3.10 and didn’t feel like changing it. I had to copy the whole environment (every single file from envs) from one machine to next, it works.

Answered By: franbel
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.