Turning ripples into waves

Virtual environment with conda

In my last post about conda I forgot to mentioned one important step! We must add my binstar channel to make python-oceans available via conda. Also, I do not think I emphasized the importance of creating virtual environments and how to create new ones. After answering questions about this over e-mail I decided summarize all the steps here for future reference.

  • Download Miniconda (or Anaconda):
    wget -O

(Be sure to download the right conda for your system!)

  • Let conda updated itself:

    chmod +x
    ./ -b
  • Add Miniconda binaries to our path

    export PATH=/$HOME/miniconda/bin:$PATH

(If this is going to become your main python you should add that line to your .bashrc. I do not use it as my main python distribution, so I use a shell script to add it to my path, call my virtual environment, and call ipython.)

  • Add my binstar channel:
    conda config --add channels

(This was the missing step! You can add more channels like this one for example.)

  • Always create a virtual environments for each job:
    conda create --yes -n virtual_env_name python=2.7

(You can change the virtual_env_name and the python version according to your needs.)

  • Activate the virtual environment:

    source activate virtual_env_name
  • Go ahead and install any python module you want. Remember that they will be installed inside the virtual environment only.

    conda install oceans
  • To create another virtual environment:

    conda create --yes -n other_virtual_env_name python=3.4

I do not use conda as my system python, so I do not add its path to my bashrc. I wrote a small script that calls,

export PATH=/$HOME/miniconda/bin:$PATH && source activate virtual_env_name && ipython

If you need to install modules to your environment remove the ipython call in the end. If you want to add packages to your main conda environment remove the source activate call.

If you want to switch between virtual environments just type source deactivate to exit the current env and source activate other_virtual_env_name to enter the new env.

In [2]:

This post was written as an IPython notebook. It is available for download or as a static html.

Creative Commons License
python4oceanographers by Filipe Fernandes is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Based on a work at