How to pin the conda

English   |   Código fuente   |   Minimap

One interesting advance feature in Conda in the capacity to pin packages from your environments so they can not be updated at all. If you are interested in that specific version of some package and not the next one because it breaks you completely or because some other reason, you are probably pinning that package (if this is not the case, you should do the pin in the way I will describe instead of adding the specific version in every command you run). But... is it possible to pin Conda itself so it does not get updated every time you try to install/update something else?

If you don't know what Conda is, you should probably go here and learn a little bit about it. For the lazy ones:

Conda is an open source package management system and environment management system for installing multiple versions of software packages and their dependencies and switching easily between them. It works on Linux, OS X and Windows, and was created for Python programs but can package and distribute any software.

One interesting behavior in Conda is that it gets updated to the latest version every time you try to install/update something else. That is a reasonable behavior in the general context but, for some specific use cases, that can be undesirable. And in the previous undesire you have the origin of the main question I raised before: is it possible to pin Conda itself so it does not get updated every time you try to install/update something else?

I have heard a lot of people saying it is impossible to pin Conda, BUT that's not the case ;-)

You can pin Conda the same way you pin any other package.

Let me show you how you can do it... is really simple. Just one line:

echo "conda ==4.0.0" > ~/anaconda/conda-meta/pinned

This will create a file called pinned containing the conda package version you are interested to keep (in this case, I choose the version 4.0.0). This pinned file should be located in the conda-meta directory from your anaconda (or miniconda) installation. Then, every time you try to install or update something, this pinned file is read by Conda and the line with the conda specific version is added to the list sent to the SAT solver, hence you will always have that specification enabled, preventing you to update to a newer conda. Nice, don't you think?

You can remove that file when you are ready to catch a new Conda version or alternative you can run conda install/update commands with the --no-pin option.

Hope this helps others! If not, at least, it was fun to play a little bit with this feature!

See you next time!

Don't forget this blog post is an ipynb file itself! So, you can download it from the "Source" link at the top of the post if you want to play with it ;-)

Comments powered by Disqus