Skip to main content

English

Install Conda packages

danger

Due to an institutional-level block by Anaconda towards BSC, caused by a change in service policies, it is currently not possible to create, update, or modify conda environments using the defaults channel. This does not affect other channels, such as bioconda or conda-forge, which contain the majority of used packages. Below is a method to solve this issue.

Requirements to install packages

Requirements to install packages networked (must have Internet access)

  • Connect to a login4 of MareNostrum5:

    mylaptop$> ssh {username}@glogin4.bsc.es
    mylaptop$> ssh {username}@alogin4.bsc.es
    IMPORTANT

    The MareNostrum5 login4 are restricted to BSC staff and are only accessible from the BSC internal network or the Virtual Private Network (VPN).

  • Check the Internet connectivity from glogin4/alogin4, for example:

    $> wget --tries=3 --timeout=5 -q --spider google.com && echo "Networked" || echo "Non-networked"
    Networked

Check the package manager

conda is a package manager that helps you install packages under Anaconda or Miniconda (a mini version of Anaconda that includes just conda, its dependencies, and Python)

  • Load Anaconda/Miniconda in the session, for example:

    $> module load miniconda3
  • Ensure you can run conda from the command line:

    $> which conda
    /apps/MINICONDA3/py39_4.10.3/bin/conda
    $> conda --version
    conda 4.10.3

Remove defaults from the Anaconda channel list:

  • This step must be performed once a conda module is loaded and will prevent commands from timing out:

      $> conda config --remove channels defaults
  • Optionally, other channels can be added to prevent conda from attempting to retrieve from defaults when no there's no specified channel.

      $> conda config --add channels conda-forge
    $> conda config --add channels bioconda

Install and manage packages

Install packages from Anaconda.org

  • Install a package:

    $> conda install SomePackage                    # Latest version
    $> conda install SomePackage=0.15.0 # Specific version
    $> conda install SomePackage py38_env # Specific Python version
    $> conda install SomePackage=0.15.0 py38_env

    Or:

    $> conda install -c SomeChannel SomePackage     # From a specific channel on Anaconda.org
    $> conda install --name myenv SomePackage # Into an existing environment "myenv" (also -n)
  • Install multiple packages at once:

    $> conda install A B C D

Update packages

  • Update a package:

    $> conda update SomePackage

Remove packages

  • Remove one or more packages:

    $> conda remove SomePackage
    $> conda remove -n myenv SomePackage
    $> conda remove A B C D

Check installed packages

  • View the list of installed packages

    $> conda list
    $> conda list -n myenv # For an existing environment "myenv"

Install non-conda packages

Python/Pip

Both pip and python are included in Anaconda/Miniconda so that you can install packages the same as at:

https://www.bsc.es/supportkc/docs/MareNostrum4/Installing%20packages/Python/english#install-and-manage-packages

IMPORTANT

pip packages do not have all the features of conda packages, so it's recommended first try to install any package with conda

R

R is also included in most Conda package managers, so you can install a version you want and install any packages there. You can find more information at the following link.

Once you have R up and running, you can either use conda to install packages or install them from R, as described here.

Work with environments

Create environments

  • Create an environment (at the default location, you may not have enough permissions):

    $> conda create --name myenv
    $> conda create -n myenv
  • Create an environment in a custom location:

    $> conda create --prefix /path/to/my/project/myenv
    $> conda create -p /path/to/my/project/myenv
  • Create an environment with a specific version of Python and multiple packages:

    $> conda create -n myenv python=3.9 A=0.15.0 B=0.21 C D
  • Create an environment from an environment.yml file:

    $> conda env create -f environment.yml

Activate/deactivate environments

  • Activate a environment:

    $> conda activate myenv                         # By name
    $> conda activate /path/to/my/project/myenv # By prefix

    Or:

    $> source activate myenv
    $> source activate /path/to/my/project/myenv
  • Deactivate a environment:

    $> conda deactivate

Check existing environments

  • View the list of the existing environments:

    $> conda env list

    Or:

    $> conda info --envs

Remove environments

  • Remove a environment:

    $> conda remove --name myenv --all
    $> conda remove -p /path/to/my/project/myenv --all

    Or:

    $> conda env remove -n myenv
    $> conda env remove -p /path/to/my/project/myenv