Python and Jupyter
This page will address some common pitfalls when working with python and related tools on a shared system like a cluster.
The following topics will be discussed in detail on this page:
All unix systems come with a system wide python installation, however for the cluster it is highly recommended to use one of the anaconda installations provided as a modules.
module avail python
module load python/XY
These modules come with a wide range of preinstalled packages.
Pip is a package manager for python. It can be used to easily install packages and manage their versions.
By default pip will try to install packages system wide, which will not be possible due to missing permissions.
The behaviour can be changed by adding
--user to the call.
pip install --user package-name
By defining the variable
PYTHONUSERBASE (best done in your bashrc/bash_profile) we change the installation location from ~/.local to a different path. Doing so will prevent your home folder from cluttering with stuff that does not need a backup and hitting the quota.
In order to use conda environments on the HPC cluster some preparation has to be done.
Remember a python module needs to be loaded all the time – see
module avail python.
conda init bash if you use a different shell replace bash by the shell of your choice
source ~/.bashrc if you use a different shell replace .bashrc if you use a different shell.
The process was successful if you prompt starts with (base).
Create a ~/.profile with the content
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
Some scientific software comes in form of a Conda environment (e.g. https://docs.gammapy.org/0.17/install/index.html).
By default such an environment will be installed to ~/.conda. However the size can be several GB therefore you should configure Conda to a different path. This will prevent your home folder from hitting the quota. It can be done by following these steps:
conda config # create ~/.condarc
Add the following lines to the file (replace the path if you prefer a different location)
You can check that this configuration file is properly read by inspecting the output of
For more options see https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html
When using Jupyter notebooks with their default configuration a hashed password will be visible in your terminal.
We can change this with a few configuration steps by adding a password protection.
First generate a configuration file by executing
jupyter notebook --generate-config
Open a python terminal and generate a password
from notebook.auth import passwd; passwd()
Add the password hash to your notebook config file
# The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = u''
c.NotebookApp.password_required = True
From now on your notebook will be password protected this comes also with the benefit that you can use bash funktions for a more convinient use.
Quick reminder how to use the remote notebook
#start notebook on a frontend (e.g. woodycap3)
jupyter notebook --no-browser --port=XXXX
on your client:
ssh -f email@example.com -L YYYY:localhost:XXXX -N
Open the notebook in your local browser at https://localhost:YYYY
With XXXX and YYYY being 4 diget numbers.
Don’t forget to stop the notebook once you are done. Otherwise you will block resources that could be used by others!
Some useful functions/alias for lazy people 😉
alias remote_notebook_stop='ssh username@remote_server_ip "pkill -u username jupyter"'
Be aware this will kill ALL jupyter processes that you own!
nohup ssh -J firstname.lastname@example.org -L $1:localhost:$1 email@example.com " . /etc/bash.bashrc.local; module load python/3.7-anaconda ; jupyter notebook --port=$1 --no-browser" ;echo ""; echo " the notebook can be started in your browser at: https://localhost:$1/ " ; echo ""
nohup ssh -J firstname.lastname@example.org -L $1:localhost:$1 email@example.com " . /etc/profile; module load python/3.7-anaconda ; jupyter notebook --port=$1 --no-browser" ;echo ""; echo " the notebook can be started in your browser at: https://localhost:$1/ " ; echo ""
If you are using a cshell remove
. /etc/bash.bashrc.local and
. /etc/profile from the functions.