Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Latest commit

 

History

History
196 lines (149 loc) · 4.97 KB

setup.md

File metadata and controls

196 lines (149 loc) · 4.97 KB

setup instructions

environment

  • Rasbperry Pis running Raspbian
  • Python ≥3.9 (required for type hinting)
    • highly recommended: a virtual environment (like venv)
  • JupyterLab for running the notebooks
  • an MQTT broker running in Docker

Raspberry Pis

Alice, Bob & Eve

Python 3

# check current Python version:
python3 --version # we need at least 3.9.

# build a newer Python version from source.
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libssl-dev libffi-dev libsqlite3-dev

wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz # or newer.
tar -xf Python-* && cd Python-*/

# these steps might take a while.
./configure --enable-optimizations && make -j 5 # ~ number of cores +1.
sudo make altinstall # altinstall leaves the original install alone.

# check if it worked:
python3.9 --version
python3.9 -c 'import ssl;print(ssl.OPENSSL_VERSION)'

cloning and initial setup

# clone the repo:
git clone 'git@github.com:bmedicke/quantum_cryptography.git' # or via https.

# switch to the repo folder:
cd quantum_cryptography

# create a virtual Python environment with the new Python:
python3.9 -m venv env

# activate the virtual environment.
source env/bin/activate
  # while working in an activated virtual environment you can
  # simply use `python` and `pip` and  skip the postfixes.

# install requirements.
pip install wheel
pip install -r requirements.txt

# enable the I2C interface for the relay shield:
sudo raspi-config
  # Interfacing options → I2C → yes.

starting the notebook

# activate the virtual environment if its not still active.
source env/bin/activate # you can deactivate the venv with: deactivate
jupyter-lab --ip=0.0.0.0 --no-browser notebooks/ # start JupyterLab.
  # the first flag binds the programm to all network interfaces so we
  # can connect to the raspberry pi via its public IP address.
  # the second flag prevents a browser from popping up.

# now visit the displayed URL with the public IP address
# from any browser running on a device in the same network.

All required libraries are installed into the virtual environment.
You have to activate the virtual environment before starting JupyterLab.

Alice

Docker & MQTT broker

# install docker:
curl -fsSL https://get.docker.com | sh

# install docker-compose outside of venv:
sudo pip3 install docker-compose

# start the MQTT broker:
sudo docker-compose up -d

# check if it's running:
sudo docker-compose ps

# to stop it:
sudo docker-compose down

configuring the code formatter

Set the default code formatter to black:

SettingsAdvanced Code FormatterJupyterlab Code FormatterUser Preferences

{
    "preferences": {
        "default_formatter": {
            "python": "black"
        }
    },
    "black": {
         "line_length": 79
    }
}

configuring shortcuts

{
  "shortcuts": [
    {
      "command": "notebook:run-cell",
      "keys": [
        ";"
      ],
      "selector": ".jp-Notebook:focus"
    },
    {
      "command": "kernelmenu:restart-and-clear",
      "keys": [
        "Ctrl L"
      ],
      "selector": ".jp-Notebook:focus"
    }
  ]
}

more JupyterLab extensions

# get a newer nodejs version for the extensions:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install nodejs -y

# Git:
pip install --upgrade jupyterlab jupyterlab-git
jupyter labextension install @jupyterlab/git

# Spellchecker:
jupyter labextension install @ijmbarr/jupyterlab_spellchecker

# Vim:
jupyter labextension install @axlair/jupyterlab_vim

used libraries

Installation without requirements.txt:

pip install paho-mqtt jupyterlab black jupyterlab-code-formatter ipywidgets
pip install smbus