Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

python - How can I get unstuck from CondaUpgradeError "A newer version of conda is required."?

I attempted to downgrade my conda version. With conda at version 4.6.2, I ran conda install conda=4.5.12. I then went to run other conda commands, but was met with the following error:

CondaUpgradeError: This environment has previously been operated on by a conda version that's newer
than the conda currently being used. A newer version of conda is required.
  target environment location: /home/selah/anaconda3
  current conda version: 4.5.12
  minimum conda version: 4.6

I am now stuck and unable to successfully run any conda commands. How can I get conda back in working order again?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The conda documentation explicitly mentions this issue in their "Troubleshooting" documentation

Conda upgrade error

Cause

Downgrading conda from 4.6.1 to 4.5.x and then trying to conda install conda or conda upgrade conda will produce a solving and upgrade error similar to the following:

Solving environment: failed
CondaUpgradeError: This environment has previously been operated on by a
conda version that's newer than the conda currently being used. A newer
version of conda is required.
target environment location: /opt/conda
current conda version: 4.5.9
minimum conda version: 4.6

Solution

Change the .condarc file. Set the parameter by editing the .condarc file directly: allow_conda_downgrades: true in conda version 4.5.12. This will then let you upgrade. If you have something older than 4.5.12, install conda 4.6.1 again from the package cache.

EXAMPLE: If my conda info says package cache : /opt/conda/pkgs and my Python version is 3.7, then on the command line, type conda install /opt/conda/pkgs/conda-4.6.1-py37_0.tar.bz2 to resolve the issue.

This should already provide enough information to at least try to recover from that problem. I decided to add a few additional informations and to rephrase it in my own words:

Solution if you downgraded to 4.5.12

Since you installed 4.5.12 you should be able to simply modify the .condarc file and include (or change) allow_conda_downgrades: true.

The documentation "Using the .condarc conda configuration file" provides the possible locations for the .condarc file:

The .condarc file is not included by default, but it is automatically created in your home directory the first time you run the conda config command.

A .condarc file may also be located in the root environment, in which case it overrides any in the home directory.

Then update to 4.6 again (or whatever version you had previously):

conda install conda=4.6.2

Then change the setting in the .condarc file back to false:

allow_conda_downgrades: false

The last step is optional but I think the default is false to protect users from metadata-corruption by old conda versions. So I would change it back after recovering from the exception.

Solution if you downgraded to 4.5.x where x is smaller than 12 (or the above did not work)

If that doesn't work or you had downgraded to an earlier version of conda 4.5.x then you have to use the other approach. Run:

conda info

Search for the line that starts with package cache :. Navigate to that directory and look for conda....tar.gz.bz2 files. Select the one that you had previously installed and then run:

conda install PATH  # <- replace the PATH with the actual path to the selected conda file

Note that you can also download the file from the anaconda channel directly and then provide the path to this downloaded file.

Last Resort (if you're desperate and nothing worked)

In case that did not work you could try brute-force approaches. Although be warned that they could do even more damage to your conda setup - treat them as last resort (e.g. when you consider uninstalling and reinstalling conda/anaconda).

For example you could also try to manually "install" it over the existing installation (again: this may not work and maybe you cannot undo this step again!):

  • Use the conda "tar.gz.bz2" file found by the previous step (or if you don't have it download it from the anaconda channel: https://anaconda.org/anaconda/conda/files)
  • Extract it into your root environment replacing existing files.
  • Hope!
  • Hope!
  • Test if it worked

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...