Setting up a user environment¶
Please notice that since 2024, the University of Vienna allows using anaconda products (anaconda and miniconda distributions) only for teaching, no research. Please use alternatives: miniforge, micromamba (av. on all department servers), mamba or pip (av. on all department servers)
Topics
- Setup a user environment using micromamba
- Setup a user environment using venv
- Include
PATH
in Notebook Kernel
Select the default kernel that should have micromamba
present, otherwise add micromamba to the file load_modules_into_jupyter.conf
or run echo micromamba > ~/load_modules_into_jupyter.conf
in a terminal or in a code cell (prepending !
).
updated: 2025.06
!module list
Currently Loaded Modulefiles: 1) micromamba/2.2.0
Using conda¶
!micromamba info
libmamba version : 2.2.0 micromamba version : 2.2.0 curl version : libcurl/8.14.1 OpenSSL/3.5.0 zlib/1.3.1 zstd/1.5.7 libssh2/1.11.1 nghttp2/1.64.0 libarchive version : libarchive 3.7.7 zlib/1.3.1 bz2lib/1.0.8 libzstd/1.5.7 envs directories : /jetfs/home/yourusername/micromamba/envs package cache : /jetfs/home/yourusername/micromamba/pkgs /jetfs/home/yourusername/.mamba/pkgs environment : base env location : /jetfs/home/yourusername/micromamba user config files : /jetfs/home/yourusername/.mambarc populated config files : /jetfs/home/yourusername/.condarc virtual packages : __unix=0=0 __linux=4.18.0=0 __glibc=2.28=0 __archspec=1=x86_64_v4 channels : https://conda.anaconda.org/conda-forge/linux-64 https://conda.anaconda.org/conda-forge/noarch base environment : /jetfs/home/yourusername/micromamba platform : linux-64
# Create a environment with conda
# use -q quiet
# -y yes to all questions
# -c [] use conda-forge FLOSS channel
# -n [] name of the environment
# add packages, e.g.: python at version 3.12 numpy an ipykernel (required for jupyter integration)
!micromamba create -q -y -c conda-forge -n myenv python=3.12 numpy ipykernel
# show available environment
!micromamba env list
Name Active Path ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── base * /jetfs/home/yourusername/micromamba modern /jetfs/home/yourusername/micromamba/envs/modern myenv /jetfs/home/yourusername/micromamba/envs/myenv
Add the new environment to your active kernels¶
This way you can choose the kernel from the Jupyterlab launcher.
!~/micromamba/envs/myenv/bin/python -m ipykernel install --user --name MYENV --display-name "Py3.12"
Installed kernelspec MYENV in /jetfs/home/yourusername/.local/share/jupyter/kernels/myenv
Activate your environment¶
Micromamba environments need to be added to the PATH
to work well. So there is an activate
function for these environments.
You just need to run this once
# initialize bash shell
$ micromamba shell init -s bash
Running `shell init`, which:
- modifies RC file: "/jetfs/home/yourusername/.bashrc"
- generates config for root prefix: "/jetfs/home/yourusername/micromamba"
- sets mamba executable to: "/jetfs/manual/micromamba/2.2.0/bin/micromamba"
The following has been added in your "/jetfs/home/yourusername/.bashrc" file
# >>> mamba initialize >>>
# !! Contents within this block are managed by 'micromamba shell init' !!
export MAMBA_EXE='/jetfs/manual/micromamba/2.2.0/bin/micromamba';
export MAMBA_ROOT_PREFIX='/jetfs/home/yourusername/micromamba';
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__mamba_setup"
else
alias micromamba="$MAMBA_EXE" # Fallback on help from micromamba activate
fi
unset __mamba_setup
# <<< mamba initialize <<<
will edit your .bashrc
. After some time you might have to do this again, when the micromamba version changed a lot (e.g.: micromamba shell reinit -s bash
)
# List available Kernels
!jupyter kernelspec list
Available kernels: myenv /jetfs/home/yourusername/.local/share/jupyter/kernels/myenv rttovv13.2 /jetfs/home/yourusername/.local/share/jupyter/kernels/rttovv13.2 enstoolsv2021.11 /jetfs/jupyterhub/alpha/share/jupyter/kernels/enstoolsv2021.11 ir /jetfs/jupyterhub/alpha/share/jupyter/kernels/ir modelling /jetfs/jupyterhub/alpha/share/jupyter/kernels/modelling python3 /jetfs/jupyterhub/alpha/share/jupyter/kernels/python3
Using virtual environment¶
# Setup a virtual Environment for your Python in the directoy: myfancyenv
!python -m venv myfancyenv
# Creates a directory with new environment
!ls myfancyenv/
bin include lib lib64 pyvenv.cfg
# Install some package into that environment
# important is ipykernel to use it within jupyterlab/notebook
!./myfancyenv/bin/pip -q install numpy scipy pandas ipykernel
WARNING: You are using pip version 19.2.3, however version 20.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# Allow this environment to be available on the LAUNCHERS (+) sign on the left
!./myfancyenv/bin/python -m ipykernel install --user --name fancy --display-name "My Python"
Installed kernelspec fancy in /jetfs/home/yourusername/.local/share/jupyter/kernels/fancy
Wait a bit and the new python environment should be available on your launchers.
!jupyter kernelspec list
Available kernels: fancy /jetfs/home/yourusername/.local/share/jupyter/kernels/fancy myenv /jetfs/home/yourusername/.local/share/jupyter/kernels/myenv
Add PATH to your user environment¶
In order to get full access to all tools installed in your local environment, add it to your PATH
.
Open your kernel.json
file located /jetfs/home/yourusername/.local/share/jupyter/kernels/myenv/kernel.json
:
{
"argv": [
"/jetfs/home/yourusername/micromamba/envs/myenv/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"env" : {
"PATH": "/jetfs/home/yourusername/.conda/envs/myenv/bin/:${PATH}",
"LD_LIBRARY_PATH": "/jetfs/home/yourusername/micromamba/envs/myenv/lib:${LD_LIBRARY_PATH}"
},
"display_name": "MYENV",
"language": "python"
}