Skip to content

Instantly share code, notes, and snippets.

@pleonard212
Last active June 28, 2023 12:16
Show Gist options
  • Save pleonard212/a82ad35fa54de9cad18f16ea34dff765 to your computer and use it in GitHub Desktop.
Save pleonard212/a82ad35fa54de9cad18f16ea34dff765 to your computer and use it in GitHub Desktop.
Bookworm on a Raspberry Pi 4 [2022]

Hardware

Tested on a Raspberry Pi 4 with 8GB RAM.

Operating Systems

Whatever else you do, make sure you are using a 64-bit OS. The combination of the arm archtecture and a 32-bit OS will greatly limit package support.

Rasberry Pi OS is based on Debian, and very recently released a 64-bit version.

Ubuntu for Raspberry Pi 64-bit is another choice.

These instructions were tested on Rasberry Pi OS 64-bit.

sudo apt-get install python3-dev default-libmysqlclient-dev build-essentials mariadb-client mariadb-server

Create a Conda virtual environment

conda create --name BookwormDB python=3.7
conda activate BookwormDB

Clone the BookwormDB software

git clone https://github.com/Bookworm-project/BookwormDB
cd BookwormDB
pip install .

Downgrade mysqlclient

New versions (2.1.0 and up) of mysqlclient deprecated neccessary functions such as escape_string().

pip install mysqlclient==2.0.3

Adjust which regex module is used.

pip install regex
sed -i 's/import re/import regex as re/g' tokenizer.py

Or by hand:

nano [your environment]/lib/python3.7/site-packages/bookwormDB/tokenizer.py

change: import re
to: import regex as re
...on line 13.

(This may not be neccessary in Python 3.8 but we are using Python 3.7 here.)

Revert to old-school mysql passwords

Versions of MariaDB 10.4 and higher don't use traditional passwords anymore. We need to go back to the future.

sudo mysql

(no user or password needed initially since modern MariaDB uses Unix sockets to authenticate by default.)

ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("");
exit

This is of course very insecure.

Building the bookworm

mkdir [name of your bookworm]

mv input.txt [name of your bookworm]/
mv jsoncatalog.txt [name of your bookworm]/
mv field_descriptions.json [name of your bookworm]/

cd [name of your bookworm]

bookworm init

clear; bookworm --log-level debug build all

Serving data via the backend API

bookworm serve

Visit http://localhost:10012/ to verify.

Optional: hack gunicorn to respond to requests from outside the Raspberry Pi itself.

nano [your environment]/lib/python3.7/site-packages/bookwormDB/wsgi.py

At the end of the file:

    options = {
        'bind': '{}:{}'.format('127.0.0.1', port),
        'workers': workers,
    }

... change 127.0.0.1 to the ip address of the Pi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment