Virtual environment with conda

Useful when root previliges are not required

Installation:

Install miniconda

User Guide

Documentation

Creating new django env

conda create --name myEnv django

source activate myEnv

source deactivate myEnv

List all envs

conda info --envs

OR

conda env list

List of packages installed in env

If env is not activated:

conda list -n myenv

If env activated:

conda list

Remove environment

conda env remove --name myenv

Exporting environment

Most often we want to export the dependencies installed in an environment. This is done by creating a .yml file

Export your active environment to a new file

conda env export > environment.yml

The first line of .yml file is the name of the environment

Create the environment from the environment.yml file:

conda env create -f environment.yml

Python packages

Installing conda defaults python binary under miniconda

/home/sankaran/miniconda3/bin/python

Using pip or conda to install python packages, installs the binary under corresponding python command in the environment

> which python
> /home/sankaran/miniconda3/bin/python
> source activate django 
>(django) which python 
>(django) /home/sankaran/miniconda3/envs/django/bin/python
> (if python is available under conda list of that environment. Otherwise, picks from miniconda3/bin, otherwise /user)
>(django) pip install numpy
> (Installs numpy under /home/sankaran/miniconda3/envs/django/lib/python/site-packages)

When using virtual envs, make sure to use the python binary under that environment

apt-get install installs python packages under python in /usr/lib/. That is, these packages will only be available for python binaries under usr/bin/