Conda Cheatsheet



See the conda cheat sheet PDF (1 MB) for a single-page summary of the most important information about using conda. Cheat sheet¶ Download the Anaconda Cheat Sheet for a quick guide to using Anaconda. « Moving Anaconda from one directory to another Frequently asked questions ». Conda config -get Get all keys and values from my.condarc file conda config -get channels Get value of the key channels from.condarc file conda config -add channels pandas Add a new value to channels so conda looks for packages in this location Conda user cheat sheet For full documentation of any command, type the command followed by -help. CONDA CHEAT SHEET Command line package and environment manager Learn to use conda in 30 minutes at bit.ly/tryconda TIP: Anaconda Navigator is a graphical interface to use conda. Double-click the Navigator icon on your desktop or in a Terminal or at the Anaconda prompt, type anaconda-navigator CONTINUED ON BACK → conda info conda update conda.

Many people have a misconception that Conda is a distribution or more particularly; a python package manager. Both Statements though are not completely wrong but neither do grasp the whole scenario. Conda, first and foremost is open-source, cross-platform package and environment manager which was originally built to regulate difficult package management issues and is a popular Python/R manager. It is released under the Berkeley Software Distribution License by Anaconda Inc.

Conda as a package manager helps you find and install packages. It provides the utility that, if you need a package that requires a different version of Python, you do not need to switch to a different environment manager.Now, lets understand its working and basic terminologies in Conda.

There are three methods of getting conda:-

  1. Installing Miniconda. Miniconda is a free,open-source,small bootstrap version of Anaconda which contains python,conda and a few other packages.
  2. Installing Anaconda. Anaconda is the most popular Python/R distribution which contains over 750 automatically installed packages along with conda and more can be installed using conda install command.
  3. If you have already installed Python or any other package manager, then just install Miniconda or Anaconda and let the installer add the conda installation of Python to your PATH environment variable without un-installing other packages.

Conda provides with a basic set of commands and these are essential in acting as the interface between the user and software.these commands can be used for
creating and modifying environments, managing queries , installing and deleting packages, defining dependencies, etc. Given below is the table (by OpenGenus) for most used and basic commands of conda:

ApplicationCode
Install a packageconda install $PACKAGE_NAME
Update a packageconda update --name $ENVIRONMENT_NAME $PACKAGE_NAME
Update package managerconda update conda
Un-install a packageconda remove --name $ENVIRONMENT_NAME $PACKAGE_NAME
Create an environmentconda create --name $ENVIRONMENT_NAME python
Activate an environmentconda activate --name $ENVIRONMENT_NAME
Deactivate an environmentconda deactivate
Search available packagesconda search $SEARCH_TERM
Install a package from specific sourceconda install --channel $URL $PACKAGE_NAME
List of installed packageconda list --name $ENVIRONMENT_NAME
Create requirements fileconda list --export
List all environmentsconda info --envs
Install other package managerconda install pip
Install Pythonconda install python=x.x
Update Pythonconda update python

Further command more specified to the task such as management of R packages, dependencies etc. can be found using help in conda or -h.

A conda environment is structured as a directory which contains packages along with their dependencies and is the interface where the user analyzes different kind ao data as per its use . This system gives the user the utility that if an environment has a different version of Python and packages,you can create and utilize a new environment without changing or deleting the former environment. You can switch between environments by activating and deactivating environment or even give someone else your environment structure by sharing your .yaml file.

Creating and managing environments
To create an environment:

to create an environment with a specific version of Python:

Create the environment from the environment.yaml file:

You can control where a conda environment lives by providing a path to a target directory when creating the environment.

You may also require to update your conda environment.The most common reasons for updating your conda environments are:-

  1. You have found a better package for data extraction and analysis.
  2. A new version of the core dependencies of the package has been released.
  3. The package is no more useful .

To see a list of all of your environments, in your terminal window or an Anaconda Prompt, run:

A list similar to the following is displayed:

Further instructions for creating similar environments , activating and deactivating environment, cloning etc. and be found using help or -h.

Conda packages include a compressed tarball of files which contain system level libraries,language modules, metadata,executable files and clusters to be directly installed in the system excluding directories.

Conda Cheatsheet

The structure of a package is pretty much the same across platforms.

Structure of a Package:

Packages are classified into various types depending on the files they contain, their architecture and use.

  • Metapackages are packages which do not contain any files and are basically used for capturing metadata and making complex packages simpler.One of the example of a Metapackage is Anaconda Installer which contains certain links from where the data is to be downloaded and dependencies for low-level libraries.
  • Noarch packages are packages which do not have a defined architecture and used to distribute source codes and docs to users. it can be built only once and are usually in python or generic.
  1. Check to see if a package you have not installed named 'fatcat' is available from the Anaconda repository (must be connected to the Internet):
    conda search fatcat
  2. Install a package into the current environment:
    conda install [packagename]

Conda channels are where bundles are put away. They fill in as the base for facilitating and overseeing bundles. Conda bundles are downloaded from URLs to registries containing Conda bundles. The Conda direction look through a default set of channels, and bundles are naturally downloaded and refreshed.
Downloading same packages from different channels cause a fault called a conda collision .Conda resolves the issue by removing the lower priority channel bundle and keeping the latter so as to not to override the core package.

Now that we are aware of the various terms associated with conda, let us understand how it works internally.
when we install Conda for the first time or install a new package in conda, the package consists of metadata and tarball of files to be installed. A tarball is a jargon for a .tar archive , in which all the files are just groped together, not compressed.
For eg. , the basic structure of a conda package for python is given below.

the installer extracts the files into the pkgs folder and hard links files from meta.yaml.once the software knows what is to be installed it starts running tests for dependencies and faults. once it is installed, the software allows to set environments as per user choice and we are able to use the software to its full utility as a package manager.

Step by step flow-

  1. Downloading and processing index metadata.
  2. Reducing the index.
  3. Expressing the package data and constraints as a SAT problem.
  4. Running the solver.
  5. Downloading and extracting packages.
  6. Verifying package contents.
  7. Linking packages from package cache into environments.

Given below is a flowchart of how conda installs packages.

A few methods can be implemented in improving the performance of the conda system likely-

  1. creating fresh environments as the older they grow the harder it becomes to resolve them. so creating small,dedicated environments can help in reducing compilation time.
  2. using specific packages instead of broad spectrum packages for use .
  3. setting strict priority controls . these will help in significantly reduce compilation time by removing mixed set of possible solutions.
  4. Another possible way of reducing compilation time is by disabling security checks, as conda spends a signification amount of the total compilation time resolving conflicts.But is is not recommended as it may crash your environment.

Before comparing the pros and cons of conda and pip , let us understand the difference between them.

pip or Python package installer is the default package manager for python whine venv is the default environment manager . Conda provides both of these utilities
in a single package.
The major pros of conda over pip is that pip only allows python packages to be installed from PyPl while conda allows every package from all languages. pip does not have in-built support for maintaining its environments and has to depend on tools lie virtualenv for maintaining them, while conda allows packages to be utilized in isolated environments , making it an extremely valuable tool for data analytics.

Anaconda Python Cheat Sheet

Also pip fails to simultaneously work all dependencies of all packages installed, conda uses a resolver to make sure all the requirements of the packages are met.

Pros:-

  1. The most significant pro of conda is the utility of managing isolated environments.As long as a package can be relocated, you can use it in multiple instances and independently for free.
  2. it can install packages in all from all available resources and can effectively maintain,manage and resolve conflicts among dependencies.
  3. Open-source ,free, multi-platform and language agnostic.
  4. It only installs binary scripts , so removes the use of a compiler.

Cons:-

  1. Since it only installs binary files leaving system packages, security patches are no longer available to you.
  2. Larger compilation time due to simultaneous running of packages.
  3. Conda fails to provide package provenance.

Anaconda Cheat Sheet Pdf

Read other Python related topics so that you can strengthen your knowledge.

I hope that this article is enough for giving a basic understanding about conda and gives a interest for it.

Managing Conda and Anaconda

conda info

conda update conda

conda update anaconda

Managing Environments

conda info --envs

conda info -e

Active environment shown with *

conda create --name snowflakes biopython

conda create -n snowflakes biopython

conda activate snowflakes

conda deactivate

conda create -n bunnies python=3.4 astroid

conda create -n flowers --clone snowflakes

conda remove -n flowers --all

conda env export > puppies.yml

conda env create -f puppies.yml

Managing Python

conda search --full-name python

conda search -f python

conda create -n snakes python=3.4

Install different version of Python in new environment

Managing .condarc Configuration

conda config --get

conda config --get channels

conda config --add channels pandas

Add a new value to channels so conda looks for packages in this location

Managing Packages, Including Python

conda list

View list of packages and versions installed in active environment

conda search beautiful-soup

Search for a package to see if it is available to conda install

conda install -n bunnies beautiful-soup

Install a new package

NOTE: If you do not include the name of the environment, it will install in the current active environment.

conda update beautiful-soup

conda search --override-channels -c pandas bottleneck

Search for a package in a specific location (the pandas channel on Anaconda.org)

conda install -c pandas bottleneck

Install a package from a specific channel

conda search --override-channels -c defaults beautiful-soup

Search for a package to see if it is available from the Anaconda repository

conda install iopro accelerate

Install commercial Continuum packages

conda skeleton pypi pyinstrument

conda build pyinstrument

Build a Conda package from a Python Package Index (PyPi) Package

Removing Packages or Environments

conda remove --name bunnies beautiful-soup

conda remove beautiful-soup

conda remove --name bunnies beautiful-soup astroid

conda remove --name snakes --all

Notes

  • Based on the cheat sheet from Conda Docs
  • Converted by Charles