1

Given the pending retirement of python 2 support in January 2020, we should be thinking about migrating from Miniconda2, which is python 2 based, to Miniconda3, which is python 3 based.

As of the date of asking this question, the Miniconda web pages don't address this topic.

Is there a good procedure for converting from Miniconda2 to Miniconda3 that will preserve the existing environments created under Miniconda2?

Traveler
  • 1,048
  • 14
  • 27
  • 1
    FYI, I ended up just leaving my existing miniconda2 environment and the python 2.7 env that existed there in place, removing all the other environments and the pkgs directory to save space. I then installed miniconda3 (with brew) and rebuilt my python 3.7 environment fresh from a script that enumerates desired packages (I highly recommend having such a script). This doesn't actually address the question, but it is what I chose. I will delete the old python 2.7 env when it remains unused for long enough to not be relevant. – Traveler Nov 17 '19 at 19:05

2 Answers2

2

You could try to upgrade your python version as suggested in this answer:

conda install python=3.7

But I'm not sure how safe that would be. (unsafe)

A safe approach is to simply install miniconda3 into a new path on your machine reproduce identically your current environments on the new miniconda installation.

To do that, you'll have to create a spec list for each of your environments in miniconda2 by:

conda activate myenv
conda list --explicit > myenv-spec-file.txt

Then under your miniconda3 installation, do:

conda create --name myenv --file myenv-spec-file.txt

The conda docs have detailed instructions on this process.

Keep in mind that when you install miniconda3, it will add an entry into your .*rc file (e.g. .bashrc, if using bash) and the new conda based on python 3 will be used when running any conda command. So you should create your spec files prior to installing miniconda3.

Edit: As pointed out by merv and nekomatic, upgrading conda in-place is not safe.

foglerit
  • 7,792
  • 8
  • 44
  • 64
  • 1
    Absolutely not safe: it is super risky to attempt updating the **base** env conda. One thing that must be ensured is that the `conda` Python package is also updated to match the Python version. – merv Nov 03 '19 at 16:33
  • I think slightly safer would be to find the corresponding conda package by first searching (e.g., `conda search conda[build=py37*]`) and then do something like `conda install python=3.7 conda=4.7.12=py37_0`, to ensure the correct build is installed. – merv Nov 03 '19 at 16:40
  • The advice to export each env to a file and use that file to recreate the env is absolutely correct, the suggestion to upgrade Python in place is absolutely wrong. Edit out the bit about upgrading and this will be a good answer. – nekomatic Nov 08 '19 at 10:31
  • @foglerit I will accept your answer if you fix it as nekomatic suggested. I myself just rebuilt top-down from my desired packages as I have hit snags with using a spec-file before. Better to just re-create and move on... – Traveler Nov 17 '19 at 19:08
0

If you're as late as me porting from miniconda2 to miniconda3... it seems you don't have to worry about losing any envs. When installing miniconda3 (into a different path than miniconda2) it found and listed all of the environments installed in my miniconda2 directory. This allowed me to clone envs into the miniconda3 directory with conda create --clone <path-to-miniconda2-env> - <new-env-name> before clearing up miniconda2, rather than relying on yml files which sometimes need alteration (although I would still recommend saving yml configs of your envs before installing miniconda3).

jasmit
  • 76
  • 3