Skip to content

Python

General information

We try to include as many Python packages as possible on all of our workstations and compute servers. However, due to the way Debian works, these may not be the most up-to-date versions or packages may not yet be included at all.

If you find that a ython module is missing you could use pip or pip3 to install t but note that this gets harder (or might even break) if you want to upgrade a package that is already included in the basic Debian. A better solution is to create a virtual environment for each project or simply use Anaconda.

Anaconda

Anaconda can be used to manage a complete Python stack inside your $HOME folder (so you can easily use the newest Python 3.7 or 3.8).

You’ll either want to download the Anaconda Linux installer from this website: https://www.anaconda.com/products/individual (x86) or use Miniconda, if you prefer a smaller distribution that comes without any of the scientific packages (which means you can pick them manually via conda install): https://docs.conda.io/en/latest/miniconda.html#linux-installers (use ‘Miniconda3 Linux 64-bit’).

Jupyter notebooks

A minor inconvenience when using Jupyter notebooks with Python environments, is that it sometimes is not clear which environment a notebook runs in.

Note

The environment of a Jupyter notebook is independed of the environment in which the jupyter notebook command was run.

A handy trick to figure out the current environment is to run the following in the beginning of a Jupyter notebook:

import sys
print(sys.executable)

To list all the available kernels to Jupyter, run this on the command line:

jupyter kernelspec list

If you find that there is no kernel available for your given environment (let’s call it myenv), proceed as follows:

# switch to the environment

conda activate myenv

# install ipykernel package in that environment

conda install ipykernel

# install the kernel itself
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

The parameter --name is used to specify the internal name of the kernel; the parameter --display-name is the name that will show up in Jupyter.

Jupyter trust db

Sometimes, the Jupyter notebook can appear to be unable to save a notebook because of an error in Sqlite (due to the database being stored in our network home folder). If this happens, a work around would be to add one of the following to the jupyter_notebook_config.py.

c.NotebookNotary.db_file = ':memory:'

or

import os
import os c.NotebookNotary.db_file = '/run/user/%i/jupyter/trustfile.db' % os.getuid()