Anaconda on Linux

Anaconda is a package and virtual environment manager. Python virtual environments are essential for developers to isolate environments between applications. The great thing about tools like this is that there are no limits to the number of virtual environments you can have since they’re just directories containing a few scripts. In this guide we will install anaconda on linux and configure it for use with neovim.

I prefer to use miniconda, it's a stripped down version of anaconda with the bare essential packages at its core, resulting in a much smaller size. To install miniconda:

Arch Linux:

yay miniconda3

You will want to only update this package through conda itself so we can tell pacman to ignore updates:

sudo vi /etc/pacman.conf

Edit this line:

IgnorePkg = miniconda3

Add miniconda3 to ~/.zshrc:

export PATH="/opt/miniconda3/bin:$PATH"

Restart zsh:

conda init zsh

Debian Linux:

Install our public gpg key to trusted store:

curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > conda.gpg
install -o root -g root -m 644 conda.gpg /etc/apt/trusted.gpg.d/

Add our debian repo:

echo "deb [arch=amd64] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" > /etc/apt/sources.list.d/conda.list
sudo apt-get update
sudo apt-get install conda

Add conda to ~/.zshrc:

export PATH="/opt/conda/bin:$PATH"

Restart zsh:

conda init zsh

Config:

Now we have miniconda installed we can create a virtual environment with python version 3.7 named 'py37':

conda create -n py37 python=3.7

Activate it:

conda activate py37

Conda-forge has a much more extensive collection of conda packages compared with base conda, let's add that channel to our sources list:

conda update conda
conda config --append channels conda-forge

Verify this:

conda config --get channel

We can now tell neovim to now use the python environment we have created:

conda install neovim

Add this to ~/.config/nvim/init.vim, replace $USER and $ENVNAME:

let g:python3_host_prog = '/home/$USER/.conda/envs/$ENVNAME/bin/python'

Set the default environment on startup, add this to ~/.zshrc:

conda activate py37

Update conda:

sudo conda update -n root conda

Update conda packages:

conda update --all

That's it!  It is strongly advised that you create a seperate environment for every app you create, that way when others collaborate with you they can reproduce the exact python environment required to run the app without encountering conflicting libraries from their own python environments.