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:-
- Installing Miniconda. Miniconda is a free,open-source,small bootstrap version of Anaconda which contains python,conda and a few other packages.
- 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. - 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:
Application | Code |
---|---|
Install a package | conda install $PACKAGE_NAME |
Update a package | conda update --name $ENVIRONMENT_NAME $PACKAGE_NAME |
Update package manager | conda update conda |
Un-install a package | conda remove --name $ENVIRONMENT_NAME $PACKAGE_NAME |
Create an environment | conda create --name $ENVIRONMENT_NAME python |
Activate an environment | conda activate --name $ENVIRONMENT_NAME |
Deactivate an environment | conda deactivate |
Search available packages | conda search $SEARCH_TERM |
Install a package from specific source | conda install --channel $URL $PACKAGE_NAME |
List of installed package | conda list --name $ENVIRONMENT_NAME |
Create requirements file | conda list --export |
List all environments | conda info --envs |
Install other package manager | conda install pip |
Install Python | conda install python=x.x |
Update Python | conda 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:-
- You have found a better package for data extraction and analysis.
- A new version of the core dependencies of the package has been released.
- 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.
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.
- 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
- 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-
- Downloading and processing index metadata.
- Reducing the index.
- Expressing the package data and constraints as a SAT problem.
- Running the solver.
- Downloading and extracting packages.
- Verifying package contents.
- 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-
- 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.
- using specific packages instead of broad spectrum packages for use .
- setting strict priority controls . these will help in significantly reduce compilation time by removing mixed set of possible solutions.
- 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:-
- 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.
- it can install packages in all from all available resources and can effectively maintain,manage and resolve conflicts among dependencies.
- Open-source ,free, multi-platform and language agnostic.
- It only installs binary scripts , so removes the use of a compiler.
Cons:-
- Since it only installs binary files leaving system packages, security patches are no longer available to you.
- Larger compilation time due to simultaneous running of packages.
- 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
|
|
|
Managing Environments
| Active environment shown with |
| |
| |
| |
| |
| |
| |
| |
|
Managing Python
| |
| Install different version of Python in new environment |
Managing .condarc Configuration
| |
| |
| Add a new value to channels so conda looks for packages in this location |
Managing Packages, Including Python
| View list of packages and versions installed in active environment |
| Search for a package to see if it is available to conda install |
| Install a new package NOTE: If you do not include the name of the environment, it will install in the current active environment. |
| |
| Search for a package in a specific location (the pandas channel on Anaconda.org) |
| Install a package from a specific channel |
| Search for a package to see if it is available from the Anaconda repository |
| Install commercial Continuum packages |
| Build a Conda package from a Python Package Index (PyPi) Package |
Removing Packages or Environments
|
|
|
|
Notes
- Based on the cheat sheet from Conda Docs
- Converted by Charles