HakoDocs

HakoDocs

Posts (Latest 10 updated) :
Read all
Table of Contents:
  1. Python: Jupyter Notebooks
    1. Installation
  2. Set Up a Remote Server
  3. Vim Bindings

Python: Jupyter Notebooks

Jupyter Notebooks are an interactive computing environment that allows users to write and execute code in a web-based interface. They support multiple programming languages (with Python being the most common) and combine code, text, equations, and visualizations in a single document. Jupyter is widely used in data science, scientific computing, and education for prototyping, data analysis, and sharing reproducible research.

Installation

Jupyter Notebooks are available via the Python Package Index.

pip install notebook

You can also install the more modern Jupyter Lab, although this guide uses the Classic Notebook package.

pip install jupyterlab

To start a server on localhost:8000 simply run.

jupyter notebook

Note: The root directory / is mapped to wherever the jupyter notebook is started.

Set Up a Remote Server

Using a remote server in Jupyter is essential when working with resource-intensive tasks that require more computing power than a local machine can provide. This is common in data science, machine learning, and scientific computing, where large datasets and complex models demand high-performance CPUs, GPUs, or specialized hardware. Running Jupyter on a remote server allows users to access powerful resources while working from a lightweight local machine, ensuring efficiency and flexibility. Here is a simple, probably not so secure method to set up a quick jupyter server in your remote machine. Taken from this article

Generate a jupyter config file with

jupyter notebook --generate-config

Open the generated file jupyter_notebook_config.py. This file is stored in the user’s home directory, i.e. these changes apply only to the current user and need to be set up for other users in case you need it. Here we will change a few configuration options.

  • Don’t start the web browser automatically.
    c.NotebookApp.open_browser = False
    
  • Listen on the local network instead of the localhost only.
    c.NotebookApp.ip = '0.0.0.0'
    
  • Don’t require a password. (For some reason I never got this to work)
    c.NotebookApp.password = ''
    
  • Set up a token (This will be the password)
    c.NotebookApp.token = 'PASSWWORD'
    
  • Optional: Change the default port. Useful when you have multiple users on the same PC.
    c.NotebookApp.port = 8888
    

TIP: In case you have multiple users/students, set up their configuration files with different ports and token passwords.

Vim Bindings

Basic Vim Bindings can be easily set up using the jupyter-vim-binding plugin. Following their documentation, run

# Create required directory in case (optional)
mkdir -p $(jupyter --data-dir)/nbextensions
# Clone the repository
cd $(jupyter --data-dir)/nbextensions
git clone https://github.com/lambdalisue/jupyter-vim-binding vim_binding
# Activate the extension
jupyter nbextension enable vim_binding/vim_binding