Jupyter Notebook
If you are coding in Python or working in data science, you most probably heard of or are using Jupyter Notebook, and/or Jupyterlab. I also have my setup and would like to document what I have done.
Preconditions
I have a normal Debian Server. Depending on your use case, some computing power may be appropriate. But that’s it.
Packages
Mainly, two packages are important for me: ffmpeg
and imagemagick
. Both are not required but nice for Sagemath as soon as you want to create some images.
Install Mamba
Conda is a very powerful manager for Python Environments. I usually prefer venv
because it is built-in to Python and a bit more flexible for development (particularly with the location of environments), but I love Conda for Jupyter Notebook where all the environments are in one place anyways.
Instead of Conda itself I will use Mamba which is a C++ implementation of Conda. It is essentially a drop-in replacement and much faster than Conda, particularly when downloading many packages (looking at you, Sagemath).
Installation is quite straight-forward. I am using the root
user because I want my base images to be readable but immutable by the user that will run Jupyter Notebook.
# Download the Installation script
wget https://github.com/conda-forge/miniforge/releases/download/${mamba_version}/Mambaforge-${mamba_version}-Linux-x86_64.sh
# Execute the Installer
sh Mambaforge-${mamba_version}-Linux-x86_64.sh
# Read and accept the BSD-3 License
# In my case: Install to /opt/mambaforge
# Allow initializing your shell if you want to;
# based on your preferences. I didn't.
And that’s it!
Install Jupyter Notebook
Separating things is always good, so we will create an own environment for that. Again, this will be done with the root
user.
mamba create -n jupyter-env jupyterlab nb_conda
Define some server settings
This now has to be done with the user that will be running the Jupyter Notebook. It’s chris
in my case, it may be different for you.
# If not done: Activate the jupyter-env
mamba activate jupyter-env
# Generate configuration file
jupyter server --generate-config
The file ~/.jupyter/jupyter_server_config.py
was created. Edit it and update or add the following lines:
# Allow connections from everywhere (assuming that the server
# will not be available online but only from your local
# network!)
c.ServerApp.ip = "0.0.0.0"
c.ServerApp.open_browser = False
Define a password
Without a password, you can only login with a token which is not nice for a server application. Setting a password is straight forward (again as user chris
):
jupyter server password
Done! The password will be written (in an encrypted form) to ~/.jupyter/jupyter_server_config.json
.
R Kernel
I have to work with the R language at university. Installing this was mostly straight-forward.
# As root - Immutable environment
mamba create -n r-env r-base r-essentials r-irkernel
Installing the Jupyter Kernel worked from the R
console, as user chris
:
IRkernel::installspec(user=TRUE)
Sagemath Kernel
My preferred Maths Programming Language. Also the reason to use Mamba over Conda. Run as root:
mamba create -n sage-10.0-env sage=10.0 python=3.11
Installing the kernel, as user chris
:
jupyter kernelspec install --user /opt/mambaforge/envs/sage-10.0-env/share/jupyter/kernels/sagemath/
Installing the kernel did raise an error for me, because the Sagemath kernel here is incomplete. Still, everything worked out and the kernel was available in Jupyter. As a cosmetic change, I just required the logo images. I just copied them there; knowing that this is not really how it should be done but it works out. For reference, I used logo-64x64.png and logo.svg and placed them in the ~/.local/share/jupyter/kernels/sagemath/
directory.
Missing: Octave (Matlab)
We are also using Octave quite some time. I did not yet install the kernel for it but I may do so in the future and maybe even update the post then. Let’s see. If you desire that, send me a message - this may motivate me to write this part too.