Page tree
Skip to end of metadata
Go to start of metadata

If you are from CGSB, please refer to NYU Gencore for software installation. Contacts: https://gencore.bio.nyu.edu/bioinformatics/

Go through the Conda 30 mins test drive to make sure you understand the basic concepts: http://conda.pydata.org/docs/using/envs.html

This page is about how to create, use and migrate your own environment using Conda on Dalma.

Creating Environment

Anaconda is based on environment. Each environment is independent. Which means you could install

  1. (One Time Setup) Install Miniconda (which is a essential version of Anaconda) to your $HOME. A preferred path is $HOME/conda. The installation could be done by following the instructions here: https://conda.io/docs/user-guide/install/index.html

  2. (One Time Setup) When it asks whether to put Miniconda to your .bashrc, say yes.

    Do you wish the installer to prepend the Miniconda install location
    to PATH in your /home/<netid>/.bashrc ? [yes|no]
  3. (One Time Setup) Log out and log in again. Now conda should be available.

    [gh50@login-0-1 ~]$ which conda
    /home/gh50/conda/bin/conda   # You should see it's under your $HOME
  4. Available Anaconda Python packages are listed here:https://docs.continuum.io/anaconda/pkg-docs. Alternatively, run the following commands to search.

    # Example: conda search ipython
    conda search <package-name>
  5. Now you can create your own environment and use it.

    # Create environment
    # This example creates an environment called dalma-python with numpy installed
    # Example: conda create --name dalma-python numpy
    conda create --name <environment-name> <python-packages>
    
  6. Once the installation is done, you could activate the environment.

    # Create environment
    # Example: source activate dalma-python
    source activate <environment-name>
    Example screen output:
    (dalma-python) [gh50@login-0-1 ~]$ 
    # (dalma-python) is the environment activated. 
  7. Once the source is activated, you could install the package you want. The package installed is local to the environment activated. E.g., if you have 2 environments, fire and ice. You installed ipython when fire is activated. Then fire will contain ipython but ice will not.

    Always install packages to your own environments. root environment is not modifiable by normal users.

    # Example: conda install scipy
    conda install <python-package> 
  8. After finalizing your environment, clean the installation cache.

    conda clean --all

Using Environment

Let say if you have followed the steps above to create an environment call dalma-python, with numpy and scipy installed in this environment. Now you want to activate this environment.

  1. (If you followed the installation instructions above, this step is not necessary): Activate Miniconda

    # If your Miniconda is installed in $HOME/conda
    export PATH=$PATH:$home/conda/bin
  2. Now conda should be available. If not, check your installation

    [gh50@login-0-1 ~]$ which conda
    /home/gh50/conda/bin/conda   # You should see it's under your $HOME


  3. (Optional) List environments available.

    conda env list

    Example output.

    [gh50@login-0-1 ~]$ conda env list
    # conda environments:
    #
    cs                       /home/gh50/conda/envs/cs
    dalma-python             /home/gh50/conda/envs/dalma-python
    root                  *  /home/gh50/conda
  4. Now activate environment dalma-python.

    source activate dalma-python

    You will see the changing of your system prompt.

    [gh50@login-0-1 ~]$ source activate dalma-python
    (dalma-python) [gh50@login-0-1 ~]$ 

    Now you will be able to use the packages installed in this environment. 

  5. (Optional)  You could check the packages installed in your active environment.

    conda list

    Example output:

    [gh50@login-0-1 ~]$ source activate dalma-python
    (dalma-python) [gh50@login-0-1 ~]$ conda list
    # packages in environment at /home/gh50/conda/envs/dalma-python:
    #
    certifi                   2016.2.28                py36_0  
    libgfortran               3.0.0                         1  
    mkl                       2017.0.3                      0  
    numpy                     1.13.1                   py36_0  
    openssl                   1.0.2l                        0  
    pip                       9.0.1                    py36_1  
    python                    3.6.2                         0  
    readline                  6.2                           2  
    scipy                     0.19.1              np113py36_0  
    setuptools                36.4.0                   py36_0  
    sqlite                    3.13.0                        0  
    tk                        8.5.18                        0  
    wheel                     0.29.0                   py36_0  
    xz                        5.2.3                         0  
    zlib                      1.2.11                        0  

    As expected, numpy and scipy are installed.

Migrating / Sharing Environment

It is possible to migrate an environment, with exact same packages and configuration. This is the beauty of Conda. Same environment, anywhere.

root environment can not be migrated.

  1. Activate the environment you want to migrate from.

    # Activate the environment you want to migrate from
    # Example: source activate dalma-python
    source activate <env-migrate-from> 
  2. Export the environment to an yml file.

    # In this example, the yml file is called environment.yml
    conda env export > environment.yml
  3. Share this yml file.
  4. The other person / machine, an identical environment could be created using this yml file.

    # In this example, the yml file is called environment.yml
    conda env create -f environment.yml

On This Page: