Conda

From Dave's wiki
Jump to navigation Jump to search

Conda is a packaging tool and installer that aims to do more than what pip does by handling library dependencies outside of the Python packages as well as the Python packages themselves. Conda also creates a virtual environment, like virtualenv does. https://stackoverflow.com/questions/20994716/what-is-the-difference-between-pip-and-conda

Conda packages are files containing a bundle of resources: usually libraries and executables, but not always. In principle, Conda packages can include data, images, notebooks, or other assets.

conda-forge (https://conda-forge.org/) is a GitHub organisation containing repositories of conda recipes. The built distributions are uploaded to anaconda.org/conda-forge and can be installed with conda. The GitHub page for the conda-forge project at https://github.com/conda-forge describes it as: "A community led collection of recipes, build infrastructure and distributions for the conda package manager."

The parameter -c (--channel) is for using additional channels to search for packages.

These are URLs searched in the order they are given (including file:// for local directories). Then, the defaults or channels from .condarc are searched (unless --override-channels is given).

conda install -c anaconda ncurses

Bioconda (https://bioconda.github.io/) is a channel for the conda package manager specialising in bioinformatics software. We can add channels using conda config.

conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge

Anaconda (https://www.anaconda.com/what-is-anaconda/) is a free and open source distribution of the Python and R programming languages for data science and machine learning related applications (large-scale data processing, predictive analytics, scientific computing), that aims to simplify package management and deployment. Package versions are managed by the package management system conda.

Miniconda is a mini version of Anaconda that includes only conda and its dependencies.

Semantic versioning

Most Conda packages use a system called semantic versioning to identify distinct versions of a software package unambiguously.

Under semantic versioning, software is labeled with a three-part version identifier of the form MAJOR.MINOR.PATCH; the label components are non-negative integers separated by periods.

Useful commands

The tool conda takes a variety of commands and arguments. Most of the time, you will use

conda COMMAND OPTIONS --SWITCH

Use --help to get help

conda install --help

Install specific version

conda install 'attrs>16,<17.3'

When installing a new package, the versions of packages to install (along with all their dependencies) must be compatible with all versions of other software currently installed.

Information about channels, location of packages, etc.

conda info

# also information on dependencies
conda info numpy=1.13.1=py36_0

Remove packages

conda remove ...

Remove unused packages and caches https://docs.conda.io/projects/conda/en/latest/commands/clean.html

conda clean --all

Updates conda packages to the latest compatible version https://docs.conda.io/projects/conda/en/latest/commands/update.html

conda update --all

List modules

conda list ncurses

Search for packages

conda search umap-learn

You can search across all channels and all platforms using

anaconda search boltons

Environments

https://conda.io/docs/user-guide/tasks/manage-environments.html

Conda environments allow multiple incompatible versions of the same (software) package to coexist on your system. An environment is simply a filepath containing a collection of mutually compatible packages. By isolating distinct versions of a given package (and their dependencies) in distinct environments, those versions are all available to work on particular projects or tasks.

# display a list of all environments
conda env list

# what packages are installed in an environment
conda list --name my_env

To create your own environment

conda create --name recent-pd python=3.6 pandas=0.22 scipy statsmodels

To activate an environment, you simply use conda activate ENVNAME. To deactivate an environment, you use conda deactivate, which returns you to the root/base environment.

To remove an environment

conda env remove --name ENVNAME

Use conda env export to recreate exactly the same environment on a different machine.

conda env export -n course-env -f course-env.yml

To create an environment from file-name.yml, you can use the following command:

conda env create --file file-name.yml -n new_env

List installed packages within an environment https://docs.conda.io/projects/conda/en/latest/commands/list.html

conda list

Troubleshooting

Don't mix packages from defaults and conda-forge https://github.com/conda-forge/geopandas-feedstock/issues/44

https://stackoverflow.com/questions/39857289/should-conda-or-conda-forge-be-used-for-python-environments