Anaconda: Difference between revisions

From Leo's Notes
This page was last edited on 22 April 2024, at 15:55.
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:


== Installation ==
==Installation==


{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 24: Line 24:
}}
}}


== Usage ==
==Usage==


{| class="wikitable"
{| class="wikitable"
! Command
!Command
! Description
!Description
|-
|-
| conda create -n env_name pip python=version
|<code>conda create -n env_name pip python=version</code>
| env_name is the name of the new environment. Packages follow.
|env_name is the name of the new environment. Packages follow.
|-
|-
| conda env [-n] list
|<code>conda env [-n] list</code>
| Lists environments. -n lists deactivated environments.
|Lists environments. -n lists deactivated environments.
|-
|-
| conda list
|<code>conda list</code>
| Environment currently activated
|Environment currently activated
|-
|-
| conda info –envs
|<code>conda info –envs</code>
| View list of packages installed on certain environment:
|View list of packages installed on certain environment:
|-
|-
| conda list -n env_name package_name
|<code>conda list -n env_name package_name</code>
| See if a certain package is installed.
|See if a certain package is installed.
|-
|-
| conda activate env_name
|<code>conda activate env_name</code>
| Activates an environment
|Activates an environment
|-  
|-  
| conda deactivate
|<code>conda deactivate</code>
| Exit from an environment
|Exit from an environment
|-
|-
| conda env remove -n env_name
|<code>conda env remove -n env_name</code>
| Removes an environment
|Removes an environment
|-
|<code>conda install package=version</code>
|Install a specific version of a package
|-
|<code>conda clean --all [--dry-run]</code>
|Cleanup unused files in the pkgs directory. Pass in <code>--dry-run</code> to see what would have been done.
|}
|}


== Tasks ==
==Tasks==
=== Setup an R environment ===
 
=== Configuration ===
Some conda configs including channels are set in the ~/.condarc file.
 
===Setup an R environment===
To create and install a particular package in a new environment, such as R:
To create and install a particular package in a new environment, such as R:
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 68: Line 78:
}}
}}


=== Setup R Bioconda ===
===Setup R Bioconda===
To get Bioconda working, you will need to add the following channels first:
To get Bioconda working, you will need to add the following channels first:


Line 96: Line 106:
}}
}}


After installing a package, it does not load and results in the following error:
{{highlight|lang=text|code=
‘GenomeInfoDbData’ was installed before R 4.0.0: please re-install it
}}
This occurred only on the account with an old version of Miniconda and was fixed by installing the latest version of Anaconda and re-running all the commands above to reinstall the package.
== Troubleshooting ==
=== Conda is stuck solving environment ===
Conda being slow or stuck at solving an environment is a common problem.  When running conda with the -vvv option, it eventually prints "Invoking SAT with clause count ###" with some ever-changing (never really decreasing) number while consuming an entire CPU core.
Anaconda has a blog post about some possible mitigations at https://www.anaconda.com/blog/understanding-and-improving-condas-performance.
Some suggestions for those running into this issue are to:
# Remove the conda-forge channel if possible. Replace it with conda-metachannel.
# Specify a specific package rather than using a broad package spec. Eg. <code>conda install conda=4.11.0</code>
# Set "<code>conda config --set channel_priority strict</code>"
# Create a fresh environment and start all over.
There are [https://github.com/conda/conda/issues/8051#issuecomment-663849490 some other solutions] that other users on GitHub reported to have helped including:
# Set conda-forge last in the channels list in <code>~/.condarc</code>
# Set <code>channel_priority to flexible</code>. (which goes against Anaconda's suggestion above)
==See Also==
*https://linuxize.com/post/how-to-install-anaconda-on-centos-7/


== See Also ==
{{Navbox Linux}}
* https://linuxize.com/post/how-to-install-anaconda-on-centos-7/
[[Category:Linux]]
[[Category:HPC]]
[[Category:LinuxUtilities]]

Latest revision as of 15:55, 22 April 2024

Installation

$ wget https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh
$ bash Anaconda3*sh

Do you wish the installer to initialize Anaconda3
in your /gpfs/home/lleung/.bashrc ? [yes|no]
[no] >>> yes

Once installed, you will need to initialize and set up conda for your shell.

$ conda init zsh

## Restart or exec your shell
$ exec zsh

## If loaded properly, your shell should have a prefix of the environment name. Defaults to 'base'
(base) $

Usage

Command Description
conda create -n env_name pip python=version env_name is the name of the new environment. Packages follow.
conda env [-n] list Lists environments. -n lists deactivated environments.
conda list Environment currently activated
conda info –envs View list of packages installed on certain environment:
conda list -n env_name package_name See if a certain package is installed.
conda activate env_name Activates an environment
conda deactivate Exit from an environment
conda env remove -n env_name Removes an environment
conda install package=version Install a specific version of a package
conda clean --all [--dry-run] Cleanup unused files in the pkgs directory. Pass in --dry-run to see what would have been done.

Tasks

Configuration

Some conda configs including channels are set in the ~/.condarc file.

Setup an R environment

To create and install a particular package in a new environment, such as R:

$ conda create -n mro_env r-essentials
$ conda activate mro_env

To deactivate, run:

(base) $ conda deactivate

Setup R Bioconda

To get Bioconda working, you will need to add the following channels first:

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

Once that is done, you can then install packages such as:

$ conda install r-metaboanalyst

Missing channels will result in a conflict and an empty UnsatisfiableError failure:

(rlang) ~ % conda create -n rmetabo -c bioconda r-metaboanalyst
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: /
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError:

After installing a package, it does not load and results in the following error:

‘GenomeInfoDbData’ was installed before R 4.0.0: please re-install it

This occurred only on the account with an old version of Miniconda and was fixed by installing the latest version of Anaconda and re-running all the commands above to reinstall the package.

Troubleshooting

Conda is stuck solving environment

Conda being slow or stuck at solving an environment is a common problem. When running conda with the -vvv option, it eventually prints "Invoking SAT with clause count ###" with some ever-changing (never really decreasing) number while consuming an entire CPU core.

Anaconda has a blog post about some possible mitigations at https://www.anaconda.com/blog/understanding-and-improving-condas-performance.

Some suggestions for those running into this issue are to:

  1. Remove the conda-forge channel if possible. Replace it with conda-metachannel.
  2. Specify a specific package rather than using a broad package spec. Eg. conda install conda=4.11.0
  3. Set "conda config --set channel_priority strict"
  4. Create a fresh environment and start all over.

There are some other solutions that other users on GitHub reported to have helped including:

  1. Set conda-forge last in the channels list in ~/.condarc
  2. Set channel_priority to flexible. (which goes against Anaconda's suggestion above)

See Also