Conda#

Structure#

  • channels: channels are like repositories from which packages can be downloaded
    eg. conda-forge is a curated, community-driven, open-source channel which is searched as first for a package to be installed

  • environments: envs are seperate spaces with their own dependencies/packages which contents do not interact with each other. It is very important for ensuring reproducibility and reusability of programs that you run. Different versions/releases of the same programs may be installed in different environments which makes sure the program will run as intended with declared dependencies because of compatibility.

Creating environments#

  • Best practice is to first create an environment file - YAML file - which will define packages to be installed within the intended environment and then create the env with the .yml file. It is best to install all packages at once, so that all of the dependencies are installed at the same time.

  • For reproducibility and reusability purposes, it is best to specify the version of each package.

  • The name of the new env will be as specified in “name” section of YAML file.

Useful commands#

  • Create yaml file:

$ vi environment.yml

# In environment.yml:
name: geoproj
channels:  
  - conda-forge
dependencies:
  - python=3.6
  • Now create an environment from the file:

$ conda env create -f environment.yml
  • Sometimes you only need one package, you can create a new env in one line like so:

$ conda install python=3.6 --channel conda-forge
  • when installing additional packages:

$ conda install PKG # when in activated env
$ conda install --name ENV PKG # when in a different env
  • to remove a package:

$ conda remove PKG # when in activated env
$ conda remove --name ENV PKG # when in a diff env

Notes about package updates#

  • Conda updates packages to the highest version in its series, so Python 3.8 updates to the highest available in the 3.x series.

  • The “conda update” command will also update the dependencies of the package you are updating. This means that if a package depends on another package, the conda update command will also update the dependency package.

  • “–no-deps”: This option prevents the conda update command from updating the dependencies of the package you are updating.

  • use “conda update –all” to update every package and its dependencies at once. Once again, it is best to update all at once.

Sources:#