Conda cheat sheet#
//
# Deactivating the activation of the base environment in Python:
conda config --set auto_activate_base false
//
#To install a package
conda install packagename
//
# specifying multiple channels when installing a package
$ conda install scipy --channel conda-forge --channel bioconda
//
# Install a package in the base environment
conda -n base packagename
//
# Create a new environment with a set of packages
conda create -n foo instrain awscli samtools python=3.8
# update conda itself
conda update conda
#To install a certain package version
conda install <pkg>=<version>
e.g.:
conda install matplotlib=1.4.3
#To install a package from a certain channel
conda install -c bioconda pybedtools
#We can upgrage packages:
conda update numpy
#Verify environment we are right now:
conda info --envs
#create a new environment with some packages installed
conda create --name bamqc numpy pandas
#activate the created environment
source activate bamqc
#deactivate the environment
conda deactivate
#installing a new environment with a new python version:
conda create --name blahblah python=2.7
#installing a new version with all python packages included in anaconda
conda create -n python2.7_env python=2.7 anaconda
#list all envs
conda env list
#remove a given env
conda env remove --name bamqc
#setting the environment variables for a specific environment:
#Read useful post:
http://www.benjaminmgross.com/conda-env-vars/
1)
$ echo $PATH
/home/benjaminmgross/anaconda/envs/my_env/
2)
$ cd PATH
$ mkdir -p ./etc/conda/activate.d
$ mkdir -p ./etc/conda/deactivate.d
3)
$ touch ./etc/conda/activate.d/env_vars.sh
$ touch ./etc/conda/deactivate.d/env_vars.sh
4)
./etc/conda/activate.d/env_vars.sh <File>
#!/bin/sh
export MY_KEY='secret-key-value'
export MY_FILE=/path/to/my/file/
5)
./etc/conda/deactivate.d/env_vars.sh <File>
#!/bin/sh
unset MY_KEY
unset MY_FILE
#activating table of contents in jupyter:
Install extensions from:
https://github.com/ipython-contrib/jupyter_contrib_nbextensions
#opening jupyter notebook on a particular working dir:
jupyter notebook --notebook-dir=/Users/yourname/folder1/folder2/
#Enter in the command mode (gray box with blue edges) and enter with ESC
# Select cells downwards:
shift+down_arrow
# Python markdown
This nbextension allows to display output generated by the kernel in Markdown cells
For example: If you set variable a in Python
a = 1.23
and write the following line in a markdown cell:
a is {{a}}
It will be displayed as:
a is 1.23
//
#save to a file all packages in an environment:
conda list --export > packages.env
#Then we can use this file to create a new environment:
$ conda create -n ch1env --file packages.env
//
*Saving an entire environment to a file:
conda env export --file env.yml
/
*Now, we can create the environment from the env.yml file:
conda env create -f environment.yml
//
#having info on the conda we have:
conda info
# especially important are the channels, because it conditions what programs are available
//
#adding bioconda channels
#The first one is optional and the order is important
(conda config --add channels r)
conda config --add channels defaults
conda config --add channels conda-forge
conda config --add channels bioconda
#Now we can install one the bioconda programs, like for example bwa:
conda install bwa
//
* Creating an environment from a yaml file:
conda env create -f environment.yml
And the contents of environment.yml is:
name: stats
dependencies:
- python=3.4
- numpy
- pandas
# create env with R and some certain basic packages
$ conda create -n r_env r-essentials r-base
# How do I prevent Conda from activating the base environment by default?
conda config --set auto_activate_base false
The first time you run it, it'll create a ./condarc in your home directory with that setting to override the default.
# How to activate the base environment if you chose not to activate conda's base environment in your current shell session
eval "$(/homes/ernesto/miniconda3/bin/conda shell.bash hook)"
# Knowing all versions of a specific package
conda search -f <packagename>
# Knowing the active channels
conda config --show channels
# Knowing the channel urls for all installed packages:
conda list --show-channel-urls