Package Management with Conda and Pip
Anaconda vs Miniconda vs “conda”
Anaconda is a free and open-source distribution of the Python programming language for scientific computing. Anaconda includes a wide selection of Python packages that are installed by default, with the ability to install more packages using the “conda” package manager program.
Miniconda is a lightweight implementation of the Anaconda distribution that provides the “conda” package manager, but does not include the large collection of scientific Python packages installed by default like Anaconda does.
“conda” is simply the package and environment manager program that allows new software to be installed. The “conda” program is available whether you choose to install Anaconda or Miniconda.
pip
Pip is a more basic package manager than conda that allows you to install software from PyPI (Python Package Index) as well as from GitHub. It works particularly well for pure Python packages, but things can get complicated when compiled code and external (non-Python) dependencies are involved.
Not all packages are available on conda, so pip is still useful even if you’re primarily using conda. All conda environments that have Python installed should also include pip by default.
pip install -e 'git+https://github.com/NCAR/esmlab.git#egg=esmlab'
-e
installs in “editable” mode
git+
at the beginning of a URL installs from a git repository
Installing and testing conda
Download and run the conda installer script
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh ./Miniconda3-latest-MacOSX-x86_64.sh
OR
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh ./Miniconda3-latest-Linux-x86_64.sh
Then open a new terminal and check to ensure the conda
program exists:
conda --version
which conda
conda gotchas
Note that the conda installation instructions recommend running conda init {shell}
, but that this will likely result in whichever Python installation was previously used by default being overridden by the new conda-provided Python. The safest way to install conda without interfering with existing Python installs would be to add the directory /path/to/miniconda/condabin
to your PATH environment variable, which will provide just the conda
program but not python
.
Behavior with shells other than bash
(tcsh
in particular) is a bit inconsistent. conda activate
does not seem to work properly in tcsh
, but you could manually set your PATH environment variable to include the appropriate environment’s bin
directory.
conda “channels”
“Conda packages are downloaded from remote channels, which are URLs to directories containing conda packages. The conda command searches a default set of channels, and packages are automatically downloaded and updated from https://repo.anaconda.com/pkgs/. You can modify what remote channels are automatically searched. You might want to do this to maintain a private or internal channel. For details, see how to modify your channel lists.” - conda documentation
Generally speaking, conda “channels” are intended to provide packages that are guaranteed to be compatible with each other. Mixing and matching packages between channels is a common source of frustration for users, so using a single source for all of your packages is generally preferred, if possible.
“conda-forge”
The conda-forge
channel is a community led collection of recipes and packages. As of June 4, 2019, There are 6862 repositories (nearly all of which represent unique conda packages) and 1373 members in the conda-forge organization on GitHub.
I usually recommend configuring conda to use conda-forge
by default:
conda config --add channels conda-forge
Installing packages
conda activate base
conda install -y python=3
conda install -y numpy xarray