Post

conda - a virtual environment manager

How to use conda package manager.

conda - a virtual environment manager

What is conda ?

  • conda is a python package, written in python
  • it helps you to create virtual environments

How is it different ?

  • Python - In conda you can also chose the version of the python you want. It will then download the version of python that you asked for and then install it for your virtual environment.
  • Channels - Conda channels are the locations where packages are stored. You can have multiple channels from where you can get packages, and you can set there priority. Also they are prebuilt packages, so you won’t have to compile the whole package yourself. Some famous channels are - conda-forge anaconda
  • History/Revisions - whenever you make some change to the environment it is stored as a revision to the environment, and if you want to revert back to a previous revision you can do that.

How to install packages ?

In conda environment you can install packages using normal pip, that will download the latest version of packages that your according the python you selected.

To install packages using conda you can use conda install pkgname. This will install packages form the conda repository. There are channels in conda, each channel is connected to a specific repository for packages.

What happens when you do conda install

When you do conda install, conda first look for the channels to which it have to search in, then it check for other dependencies and conflicts and find a suitable match which package to install, which package to upgrade and which to downgrade to meet the user need.

This take more time if the metadata is more and more packages are installed in an environment through conda. So it is advised to install all the packages in the starting when creating an environment.

Some sample commands

  • conda activate - activate the default base environment
  • conda activate envname - activate the envname environment
  • conda deactivate - deactivate the active environment
  • conda config --set auto_activate_base false - this will create a .condarc file in the home directory and then add this option there. This option will stop the base environment form activating automatically every time you start a shell.
  • conda create --name env - create a environment with name env
  • conda create -n temp python=3.4 - crete a env temp with python 3.4 version
  • conda list - List linked packages in a conda environment.
  • conda info - Display information about current conda install.
  • conda info -e - Display information about all the conda env.
  • conda install -c channel-name pkg install pkg form channel channel-name
  • conda install ipykernel - install ipykernel in current env so we can open it in jupiter notebook.
  • conda update --all --yes - update all packages
  • conda remove --name env --all - remove env package
  • conda config --show channels - show list of channels for current env
  • conda config --show default_channels - show default channels
  • conda config --add channels channel-name - add channel channel-name to current env
  • conda config --get channels - show channels and there priority also.
  • conda config --set channel_priority strict - set the channel priority to strict
  • conda list --revision - show the list of revisions a env have
  • conda search -f pkg - search for a package in conda.
  • conda clean - Remove unused packages and caches.

References

This post is licensed under CC BY 4.0 by the author.