Conda (Miniconda) Cheatsheet: Essential Commands You Should Know

TLDR:

This cheatsheet is a summary of the common commands I use. It serves as a quick reference to the most important Conda (Miniconda) commands and as a reminder for myself.

What is Conda?

Conda is a package and environment management system, widely used in the Python and data science community. It allows you to separate projects into environments and install packages into them, making it easy to manage dependencies and avoid conflicts between packages. It also helps to replicate a specific environment in another computer.

MiniConda is a minimal installer for Conda. It includes only Conda, Python, and a few essential packages, and it's managed thought the terminal.

Essential Conda Commands:

1. Installing Conda (Miniconda):

  • Download Miniconda: Visit the official Miniconda page and download the installer for your OS.
  • Install Miniconda: Follow the installation instructions provided on the download page. In Linux that means running the following:
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh # if you don't want to keep the installer

You need to initialize conda for your shell for it to work:

~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh

and restart your terminal or run source ~/.bashrc or source ~/.zshrc for the changes to take effect.

2. Managing Environments:

  • Create an Environment: conda create --name myenv
  • Activate an Environment: conda activate myenv
  • Deactivate an Environment: conda deactivate
  • List all Environments: conda env list
  • Remove an Environment: conda env remove --name myenv
  • Clone an Environment: conda create --name myclone --clone myenv
  • Create an Environment from a File: conda env create -f environment.yml
  • Update an Environment from a File: conda env update -f environment.yml
  • Export an Environment to a File: conda env export > environment.yml

  • Export an Environment to a File (including Conda itself): conda list --explicit > environment.yml

  • Create an Environment from a File (including Conda itself): conda create --name myenv --file environment.yml
  • Update an Environment from a File (including Conda itself): conda update --name myenv --file environment.yml

3. Managing Packages:

from Conda:

this is the main and default repository for conda packages.

  • Install a Package: conda install numpy
  • Uninstall a Package: conda remove numpy
  • List Installed Packages: conda list
  • Update a Package: conda update numpy
  • Search for a Package: conda search numpy

from conda repositories:

There are alternative repositories to the default one, such as conda-forge and bioconda. You can install packages from these repositories by specifying the channel.

  • Install a Package from conda-forge: conda install -c conda-forge numpy
  • Install a Package from bioconda: conda install -c bioconda numpy

from Pip:

Some packages are not in conda, so you need to use pip to install them. pip is the default package manager for Python.

  • Install Pip, if its not installed: conda install pip
  • Install a Package: pip install numpy

4. Updating Conda:

To update conda itself, you need to update the base environment. This means deactivating the environment you are in and updating the base environment.

  • Update Conda: conda update conda

5. Exporting and Importing Environments:

  • Export Environment: conda env export > environment.yml
  • Create Environment from a File: conda env create -f environment.yml

6. Miscellaneous Commands:

  • List Conda Commands: conda --help
  • Check Conda Version: conda --version

References:

  • [Conda Official Documentation](https://docs.conda.io/projects/conda/en/latest/commands/index.html

Comments

Comments powered by Disqus