Conda
Conda is a language-agnostic package manager that operates across multiple platforms and enables users the installation and management of packages from both the Anaconda repository and the Anaconda Cloud.
Its packages are in binary form. It means that they are pre-compiled, executable files ready to be installed and run on a system, as opposed to the source code, which would require a pre-compilation. Binaries can be optimized for various OSs, making installing and running software easier without worrying about compatibility issues.
This package manager was created to address complex package management challenges faced by Devs and data scientists. Over time, it has evolved into a widely-used package manager for various programming languages, including Python, R, Ruby, Lua, Scala, Java, JavaScript, C/C++, Fortran, and more.[3]
Conda vs. Pip
Conda and pip are package managers typically perceived as synonymous, helping Devs to run commands. Despite having some similarities in functionality, these two tools were designed for distinct purposes.
Pip enables users to easily install, upgrade, remove packages, and manage dependencies. It integrates with the Python Package Index (PyPI) and provides a way to connect to other package repositories.
On the other hand, Conda is an open-source and language-agnostic package manager that allows users to install and manage Conda packages. These packages are not limited to Python but also programming languages like C, C++, or R.[4]
The following table compares these packages, highlighting the differences and the input method.
Task | Conda package and environment manager command | Pip package manager command |
Install a package | conda install $PACKAGE_NAME | pip install $PACKAGE_NAME |
Update a package | conda update –name $ENVIRONMENT_NAME $PACKAGE_NAME | pip install –upgrade $PACKAGE_NAME |
Update package manager | conda update conda | Linux/macOS: pip install -U pip Win: python -m pip install -U pip |
Uninstall a package | conda remove –name $ENVIRONMENT_NAME $PACKAGE_NAME | pip uninstall $PACKAGE_NAME |
Create an environment | conda create –name $ENVIRONMENT_NAME python | X |
Activate an environment | conda activate $ENVIRONMENT_NAME* | X |
Deactivate an environment | conda deactivate | X |
Search available packages | conda search $SEARCH_TERM | pip search $SEARCH_TERM |
Install package from specific source | conda install –channel $URL $PACKAGE_NAME | pip install –index-url $URL $PACKAGE_NAME |
List installed packages | conda list –name $ENVIRONMENT_NAME | pip list |
Create requirements file | conda list –export | pip freeze |
List all environments | conda info –envs | X |
Install other package manager | conda install pip | pip install conda |
Install Python | conda install python=x.x | X |
Update Python | conda update python* | X |
If you want to learn more about the various commands available in Conda, check this Conda Cheat Sheet.
Quick Installation Guide
The Conda package is included in all versions of Anaconda Python Distribution and Miniconda. If you want to install Anaconda, follow these instructions:
- Access the Anaconda website.
- Click on the Products button and select Anaconda Distribution.
- Download the installer at the bottom of the website according to your OS (Windows, Linux, or macOS). Here you can find old versions.
- Run the *.exe file and accept the installation terms.
- Configure the installation settings to suit your requirements.
Note: Miniconda provides a convenient way to set up a minimal installation that consists of only the essential components. This lightweight installation method is helpful for those who want to save disk space and only install the necessary components for their project.
Conda Fundamentals
Installing Packages
Conda packages are designed to be cross-platform and compatible with the Anaconda Python Distribution, ensuring that you can use them on any operating system, including Windows, macOS, and Linux.
Either way, installing packages is a straightforward process. For example, run the “conda list” command to display all the packages installed on your system.
conda list
# Name Version Build Channel _ipyw_jlab_nb_ext_conf 0.1.0 py39haa95532_0 aiohttp 3.8.1 py39h2bbff1b_1 aiosignal 1.2.0 pyhd3eb1b0_0 alabaster 0.7.12 pyhd3eb1b0_0 anaconda 2022.05 py39_0 anaconda-client 1.9.0 py39haa95532_0 anaconda-navigator 2.1.4 py39haa95532_0 anaconda-project 0.10.2 pyhd3eb1b0_0 anyio 3.5.0 py39haa95532_0 appdirs 1.4.4 pyhd3eb1b0_0 argon2-cffi 21.3.0 pyhd3eb1b0_0 argon2-cffi-bindings 21.2.0 py39h2bbff1b_0 arrow 1.2.2 pyhd3eb1b0_0 astroid 2.6.6 py39haa95532_0 …
If you’re looking for another package, the Anaconda Web Navigator provides an easy way to discover what’s available. For example, to install the Flask package, run the following command in your terminal or Anaconda Prompt:
conda install -c anaconda flask
However, not all packages are available in the Conda repository (e.g., sty); in that case, you’ll need to look it up in the PyPI repository.
In addition, Anaconda gives developers the freedom to choose between different IDEs, including Jupyter Notebook, Spyder, JupyterLab, and more. When using Jupyter Notebook, users must employ the “!pip” command in a code cell. The “!” symbol denotes the characteristic format to run commands. To install the matplotlib package, use:
!pip install matplotlib
Once the installation is complete, you have to import the package.
import numpy as np
Virtual Environments
Conda’s versatility extends beyond package management, as it also serves as a virtual environment manager. It means you don’t have to switch to another manager if you need a package requiring a different Python version. With a few simple commands, you can easily create a different environment to run that specific version of Python.
For Linux distributions, the “(base)” environment is automatically set in the terminal. You can check this using the following command.
conda config --show | grep auto_activate_base
To deactivate the environment, you can use the “False” flag.
conda config --set auto_activate_base False source ~/.bashrc
To reactivate the “(base)” environment, use the “True” flag.
conda config --set auto_activate_base True source ~/.bashrc
For users who want to create a new environment, Conda provides a straightforward way by typing the command:
conda create –name ENVIRONMENT_NAME python=3.10
To activate the environment, use
conda activate ENVIRONMENT_NAME
To deactivate the environment, use
conda deactivate
Finally, to list the available environments in your system, use
conda env list
Note: Windows users who have installed Anaconda can employ the commands described in this article. These commands perfectly match with Linux distributions method.
Highlights
Project Background
- Project: conda.io
- Author: Authors that have made at least one contribution.
- Initial Release:
- Type: Package Management System
- License: Berkeley Source Distribution (BSD)
- Contains: command-line interface, distributions of python.
- Language: Python, R, Ruby, Lua, Scala, Java, JavaScript, C/C++, Fortran, and more.
- GitHub: link
- Runs On: OS-agnostic
- Twitter: /pypi
Main Features
- It can be used on Windows, macOS, and Linux, making it a versatile tool.
- It helps users manage packages and dependencies.
- It enables the creation of working environments, allowing users to have different packages and dependencies for different projects.
- It is an open-source project with a large and active community that contributes to its development and supports its users.
- It can be integrated with other tools and platforms, such as Jupyter Notebook, PyCharm, and Visual Studio Code.
Prior Knowledge Requirements
- Users should understand how to navigate the file system and run commands from the terminal or command prompt.
- Users should have a basic understanding of Python or another programming language.
- Users should know how to create and manage virtual environments and how they are used in Python.
Community Benchmarks
- 5,100 Stars
- 1,300 Forks
- 389+ Code contributors
- Source: GitHub
Releases
- 23.1.0 (1-2023): Bug fixes. e.g., Detect CUDA driver version in subprocess.
- 22.11.0 (11-30-2022): Enhancements and Bug fixes. e.g., Improve CLI warning.
- 22.9.0 (9-20-22): Enhancements and Bug fixes, and switch to the CalVer versioning system.
- 4.14.0 (8-3-2022): Enhancements and Bug fixes. e.g., Implementation of a new rename subcommand.
- 4.13.0 (5-19-2022): Enhancements and Bug fixes. e.g., Introducing “clean –logfiles” to remove logfiles generated by libmamba-solver.
- Source: releases.
References
[1] GitHub.
[2] Anaconda website.
[3] Documentation.
[4] Anaconda blog post.