Skip to content

Instantly share code, notes, and snippets.

@nsarode
Last active October 27, 2020 17:24
Show Gist options
  • Save nsarode/e37f3284c11d69192b905fe998553b2a to your computer and use it in GitHub Desktop.
Save nsarode/e37f3284c11d69192b905fe998553b2a to your computer and use it in GitHub Desktop.
Conda environment installation, setup, use and tips & tricks. [#conda #anaconda #python]

Most used commands

# Get list of already set up environments
conda env list

# Create an environment with specified python version
conda create -n py36 python=3.6 anaconda

# Create environment without prompting for yes/no and quiet mode

conda create -y -q -n py36 python=3.6

# Activate an already setup environment
conda activate envName

# Close the conda environment
conda deactivate envName

# Install packages
conda install packagename

# Delete a no longer used environemnt

conda remove -n envName --all

## Export environment 

conda activate envName
conda env export > environment.yml

Download

Appropriate version from here e.g. v.3.5.1.0 for linux

Original manual for installation instructions here

Install

bash Anaconda3-5.1.0-Linux-x86_64.sh

Optional

Check if you ~/.bash_profile file contains path to Anaconda bin. On my mac, the installer autmatically exported its path, but on my linux machine, I had to do it manually. You will get a conda command not found error if the path is missing.

Add the following line to your ~/.bash_profile file

export PATH="$HOME/anaconda3/bin:$PATH"

Source to make sure the changes take for the current terminal session

source ~/.bash_profile

Setting up custom environments

You can search Anaconda website to see the wide list of packages that could be installed and setup. The most common ones are Python versions (2.7, 3.6), numpy.

Using Python 3.6 setup as an example:

You can give the environment any name of your choosing. But using a short descriptive one like below is good practice

conda create -n py36 python=3.6 anaconda

Activate this newly created environment

conda activate py36

Check if everything is ok

python --version

You can now install local packages of our choosing in this python environment !

After you are done, simply close the environment

conda deactivate

Available environments

If you set up environments a while back and don't quite remember what the names were, you can always check using conda env list

Or

conda info --envs

Sanity check

conda info

If you are an advanced user needing more details

conda info -a

Setup channels

conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge

Update

Commands in order of preference

conda update conda

Or

conda update -n base -c defaults conda

or

conda update -n base conda

Uninstall

Remove entire installation directory

rm -rf ~/anaconda3

Remove hidden files

rm -rf ~/.condarc ~/.conda ~/.continuum

Export environment (including exact versions of tools)

Source: https://github.com/thw17/BIO598_Tutorial

source activate envName
conda env export > environment.yml

Delete the last line (with prefix) to make it truly usable by others

sed '$d' environment.yml > environment.yml ## not checked

sed -i.bak '/^prefix/d' environment.yml

conda env create -f environment.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment