How to install Miniconda - Anaconda in the Researcher Workbench

  • Updated

In the Researcher Workbench, you can install Miniconda via the terminal. Miniconda is a minimal installer for the Anaconda distribution, which is widely used for managing packages and environments in Python and R programming. Miniconda serves as an excellent choice for users who prefer a more streamlined and customizable approach to package and environment management in their workflows. Using Miniconda, you can easily install, update, and remove packages using the command-line interface. 

How to add a Miniconda in the Researcher Workbench (terminal)

# Create the directory ~/miniconda3 if it does not already exist
mkdir -p ~/miniconda3

# Download the latest Miniconda3 installer for Linux x86_64 architecture
# and save it as ~/miniconda3/miniconda.sh
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh

# Run the Miniconda3 installer script in batch mode (-b), update the installation (-u),
# and specify the installation path as ~/miniconda3 (-p ~/miniconda3)
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3

# Remove the Miniconda3 installer script after the installation is complete
rm ~/miniconda3/miniconda.sh

# initialization:
~/miniconda3/bin/conda init bash

# use immediately in the current shell session
source ~/.bashrc

# check conda environments
conda info --env
# Locate the path to the conda executable
which conda

How to install Anaconda in the Researcher Workbench (in the terminal)

# check here, https://repo.anaconda.com/archive/, for the latest version
# download
mkdir -p ~/anaconda3
wget https://repo.anaconda.com/archive/Anaconda3-2024.06-1-Linux-x86_64.sh -O ~/anaconda3/anaconda.sh
# install
bash ~/anaconda3/anaconda.sh -b -u -p ~/anaconda3
rm ~/anaconda3/anaconda.sh
# initiate
~/anaconda3/bin/conda init bash
source ~/.bashrc

How to add a conda environment to Jupyter notebook (python)

After following the directions above, in the terminal run the code below:

#Create a new env and skip the prompt
conda create -n py312 python=3.12 -y

#Activate this environment
conda activate py312

#Install ipykernel inside the environment
pip install ipykernel

#Register the environment as a jupyter kernel
python -m ipykernel install --user --name=py312 --display-name "python(py312)"

#Check the kernel’s location
jupyter kernelspec list

#Check python version
python --version

#Check new pythonn location
which python

#Now go back to the notebook user interface (UI), click `File -> Open`, and then click `New`, will see this new kernel,
#Open a new notebook with this new kernel
#Double check new python version/location
import sys
print(sys.version)
print(sys.executable)

#To explicitly install tools in this env
#You can either install tools within the notebook
import sys
!{sys.executable} -m pip install pandas

#or you can install tools in the terminal
pip install seaborn

#Check tool installation in the terminal or within the notebook
import pandas as pd
print(pd.__version__)

import seaborn as sns
print("Seaborn version:", sns.__version__)

#For some tools, you may need to restart the kernel after installation

How to add a conda environment to Jupyter notebook (R)

# create a new R env with r-base and r-irkernel
conda create -n r_new r-base r-irkernel -c conda-forge -y
conda activate r_new

#register the environment as a jupyter kernel
Rscript -e "IRkernel::installspec(name = 'r_new', displayname = 'R (r_new)')"

#Now go back to the notebook user interface (UI), click `File -> Open`, and then click `New`, will see this new kernel,
#Open a new notebook with this new kernel
# within notebook, check R version
R.version

# to install R packages, install pre-compiled via Conda (Recommended)
conda install -c conda-forge r-data.table

# now within notebook or in the terminal R env, to load the package
library(data.table)

# be aware, if you prefer using install.packages(), then you man have to install extra dependencies for some tools, i.e., you have to follow
# these lines to install.packages("data.table")
conda install -c conda-forge zlib
install.packages("data.table")

# some tools can be using install.packages() direclty, i.e., this may take up to 25mins
install.packages("rms")
# however, using pre-compiled via Conda will be much faster
conda install -c conda-forge r-rms

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Article is closed for comments.