Conda is an open-source package management and environment management system that helps you install, manage, and organize packages and their dependencies. Conda allows you to create isolated environments for different projects, each with its own set of packages and dependencies, helping to avoid conflicts and ensure reproducibility.
-
Conda:
- Conda is essentially the package manager. Your new best friend. It can be invoked by calling the command conda.
-
Anaconda:
- This is a full system, including sci packages, designed for python. It is a large, multi gigabyte install.
-
Miniconda:
- This is the mini-installer of Conda and probably what you want. It contains conda package manager and will require you to install each package manually. This is usually the preferred way to use conda. If you are in doubt still, install Miniconda.
To install Anaconda or preferably Miniconda on a Mac, the most common way is through Brew. Install brew. Then open a terminal and install Miniconda.
brew install --cask miniconda
or
brew install --cask anaconda
To install on Windows download the package for Miniconda from conda.io here: Miniconda Installer
-
Create a new Conda environment: (stick with lowercase env names for filesystem compat)
conda create --name myEnvName
-
Activate an environment:
conda activate myEnvName
-
Deactivate the current environment:
conda deactivate
-
Clone an environment:
conda create --clone myEnvName --name newEnvName
-
Install a package:
conda install packageName
-
Install a specific package version:
conda install packageName=1.2.3
-
Update a package:
conda update packageName
-
Update all packages in the current environment:
conda update --all
-
Remove a package:
conda remove packageName
-
List installed packages:
conda list
-
Export environment to a YAML file:
conda env export > environment.yml
-
Create an environment from a YAML file or install into existing environment from a YAML file:
conda env create -f environment.yml
conda env update -n existing_env_name -f environment.yml
-
Remove an environment:
conda env remove --name myEnvName
-
List all environments:
conda info --envs
Channels and sources are remote repositories where packages are stored. The default channel will work properly in most cases, but here are some additional commands for channel / source management.
-
Add a channel:
conda config --add channels channelName
-
Search for packages in a specific channel:
conda search -c channelName packageName
-
Specify channel priority:
conda config --set channel_priority strict
-
Install a specific Python version:
conda install python==3.8
-
Create a virtual environment for a specific Python version:
conda create --name pyEnvName python==3.8
Many people are not aware, but Conda is not just an environment and package manager for python. It also supports languages like R, Lua and C. Here are some basics to get you started using Conda with other languages.
-
Install R language in an environment:
conda install -c r r-base
-
Create a Conda environment with R:
conda create --name r_env r=4.1.1
-
Install R packages using Conda:
conda install -c r r-essentials
-
Install Ruby in an environment:
conda install -c conda-forge ruby
-
Create a Conda environment with Ruby:
conda create --name rubyEnvName ruby=2.7
-
Install Ruby gems using Conda:
conda install -c conda-forge rb-gemName
-
Install Lua in an environment:
conda install -c conda-forge lua
-
Create a Conda environment with Lua:
conda create --name luaEnvName lua=5.4
-
Install LuaRocks packages using Conda:
conda install -c conda-forge lr-rockName
-
Install C++ tools and libraries:
conda install -c conda-forge gxx cmake
-
Create a Conda environment for C++ development:
conda create --name cppEnvName gxx cmake
-
Use CMake to build C++ projects in Conda environment:
mkdir build && cd build conda activate cppEnvName cmake .. make
-
Show Conda information:
conda info
-
Display environment details:
conda info --env
-
Check for package updates:
conda search --outdated
-
Create a virtual environment for Python 3.9:
conda create --name py3EnvName python=3.9
-
Enable Jupyter Notebook or Jupyter Lab in an environment:
conda install -c conda-forge notebook conda install -c conda-forge nb_conda_kernels
conda install -c conda-forge jupyterlab conda install -c conda-forge nb_conda_kernels
-
List available Conda commands:
conda --help
-
Update Conda itself:
conda update conda
-
Export environment variables to a file:
conda env export --no-builds > environment.yml
-
Create an environment with specific packages:
conda create --name myEnvName packageName1 packageName2
-
Create a new environment with a specific path: (stick with lowercase names for Conda envs)
conda create --prefix /path/to/myEnvName
-
Install packages from a requirements file:
conda install --file requirements.txt