Home

Recent
Archive

Numerical experiments, Tips, Tricks and Gotchas

Numerically speaking

Conda Virtual Environments

Virtual Environments

virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need. See e.g. these refetences [1], [2], [3]. virtualenvwrapper is a set of extensions to the virtualenv tool. [4].

Conda Virtual Environments

Conda is an open source package management system and environment management system for installing multiple versions of software packages and their dependencies and switching easily between them [5]. It comes with Anaconda Python distribution [6].

Conda virtual environment commands slightly differ from virtualenv [7], [8], [9].

Create a virtual environment for a project

$ conda create -n ve_name python=x.y anaconda
$

This will install the Python version and all the associated anaconda packaged libraries at "path_to_your_anaconda_location/anaconda/envs/yourenvname".

Activate your virtual environment

$ source activate ve_name
(ve_name)$

Deactivate

(ve_name)$ source deactivate
$

Completely delete a virtual environment

$ conda remove -n ve_name -all

Anaconda with both python 2 and 3

Conda provides easy switch between different versio of Python [10], [11].

1. Anaconda with Python 2 installed as a default (short instruction)

$ conda update conda
$ conda create -n py33 python=3.3 anaconda
$ source activate py33
. . .
(py33)$ source deactivate
$

2. Anaconda with Python 3 installed (long instruction with output)

$ conda update conda
$ conda create -n py27 python=2.7 anaconda
To activate this environment, use:
$ source activate py27
      discarding /Users/nikolai/anaconda/bin from PATH
      prepending /Users/nikolai/anaconda/envs/py27/bin to PATH
(p27)$
To check the active environment, use:
(py27)$conda info -e
      # conda environments:
      #
      py27                  *  /Users/nikolai/anaconda/envs/py27
      root                     /Users/nikolai/anaconda
(py27)$
To deactivate this environment, use:
(py27)$ source deactivate
      discarding /Users/nikolais/anaconda/envs/py27/bin from PATH
$conda info -e
      # conda environments:
      #
      py27                     /Users/nikolai/anaconda/envs/py27
      root                  *  /Users/nikolai/anaconda
$

Note: On Windows to activate this environment, use:

 activate py27
C:\Users\Dr._Nikolai>conda info -e
# conda environments:
#
py27                     C:\Anaconda3\envs\py27
root                  *  C:\Anaconda3

Note: On Windows to deactivate this environment, use:

 deactivate py27

Remark: For the native Python 3 creation of virtual environments check [12].


References

  1. Virtualenv
  2. Virtual Environments
  3. A non-magical introduction to Pip and Virtualenv for Python beginners
  4. virtualenvwrapper
  5. Conda
  6. Anaconda-Quickstart
  7. Create virtual environments for python with conda
  8. Python Packages and Environments with conda.
  9. Conda FAQ
  10. Installing Python 3.3 on Anaconda Python for Windows
  11. Install a different version of Python
  12. venv - Creation of virtual environments

 

© Nikolai Shokhirev, 2012-2017

email: nikolai(dot)shokhirev(at)gmail(dot)com

Count: