How to run the code on Termux Android app - yeyeto2788/OpenNoteScannerPDF GitHub Wiki

How to run the OpenNoteScanner PDF generator server on Termux Android app

While I was looking a free solution to host the server of the PDF creator I encounter a way to run the server within Android OS with Termux app, in this guide I have written down the steps I followed in order to have the server running locally.

Update and upgrade the system

apt update && apt upgrade

Setup storage (Optional)

This step is no really required but I wanted to access to all files just in case something would failed.

In order to setup the storage just run the following command:

termux-setup-storage

If you want to access to the files follow this guide

Install Python:

In order to run python applications we need to install python 3 as in the following guide

$ pkg install python

Install system dependencies to compile some modules:

$ pkg install clang python-dev cmake pkg-config libjpeg-turbo-dev libpng-dev

You should get an output like this:

$ pkg install clang python-dev cmake pkg-config libjpeg-turbo-dev libpng-dev
Hit:1 https://termux.net stable InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version (3.7.2-2).
The following additional packages will be installed:
  binutils libllvm ndk-sysroot glib jsoncpp libarchive libexpat libjpeg-turbo
  libpng libuv libxml2 pcre rhash
The following NEW packages will be installed:
  binutils clang libllvm ndk-sysroot cmake glib jsoncpp libarchive libexpat
  libjpeg-turbo libjpeg-turbo-dev libpng libpng-dev libuv libxml2 make
  pcre pkg-config rhash
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.2 MB of archives.
After this operation, 143 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://termux.net stable/main aarch64 libxml2 aarch64 2.9.9 [358
kB]
Get:2 https://termux.net stable/main aarch64 libarchive aarch64 3.3.3-1
[220 kB]
Get:3 https://termux.net stable/main aarch64 libexpat aarch64 2.2.6 [40.0
kB]
Get:4 https://termux.net stable/main aarch64 jsoncpp aarch64 1.8.4-2
[62.4 kB]
Get:5 https://termux.net stable/main aarch64 libuv aarch64 1.26.0 [43.8
kB]
Get:6 https://termux.net stable/main aarch64 rhash aarch64 1.3.8 [126 kB]
Get:7 https://termux.net stable/main aarch64 make aarch64 4.2.1-2 [77.8
kB]
Get:8 https://termux.net stable/main aarch64 cmake aarch64 3.13.4-1 [3130
kB]
Get:9 https://termux.net stable/main aarch64 pcre aarch64 8.43 [107 kB]
Get:10 https://termux.net stable/main aarch64 glib aarch64 2.58.3-1 [700
kB]
Get:11 https://termux.net stable/main aarch64 libjpeg-turbo aarch64 2.0.2
[109 kB]
Get:12 https://termux.net stable/main aarch64 libjpeg-turbo-dev aarch64
2.0.2 [33.1 kB]
Get:13 https://termux.net stable/main aarch64 libpng aarch64 1.6.36-1
[67.8 kB]
Get:14 https://termux.net stable/main aarch64 libpng-dev aarch64 1.6.36-1
[122 kB]
Get:15 https://termux.net stable/main aarch64 pkg-config aarch64 0.29.2
[24.2 kB]
Get:16 https://termux.net stable/main aarch64 binutils aarch64 2.32-1
[1518 kB]
Get:17 https://termux.net stable/main aarch64 ndk-sysroot aarch64 19b
[1392 kB]
Get:18 https://termux.net stable/main aarch64 libllvm aarch64 7.0.1-1
[9796 kB]
Get:19 https://termux.net stable/main aarch64 clang aarch64 7.0.1-1 [13.5
MB]
Fetched 26.2 MB in 5s (4515 kB/s)
Selecting previously unselected package binutils.
(Reading database ... 1822 files and directories currently installed.)
Preparing to unpack .../binutils_2.32-1_aarch64.deb ...
Unpacking binutils (2.32-1) ...
Selecting previously unselected package ndk-sysroot.
Preparing to unpack .../ndk-sysroot_19b_aarch64.deb ...
Unpacking ndk-sysroot (19b) ...
Selecting previously unselected package libllvm.
Preparing to unpack .../libllvm_7.0.1-1_aarch64.deb ...
Unpacking libllvm (7.0.1-1) ...
Selecting previously unselected package clang.
Preparing to unpack .../clang_7.0.1-1_aarch64.deb ...
Unpacking clang (7.0.1-1) ...
Selecting previously unselected package libxml2.
(Reading database ... 3935 files and directories currently installed.)
Preparing to unpack .../00-libxml2_2.9.9_aarch64.deb ...
Unpacking libxml2 (2.9.9) ...
Selecting previously unselected package libarchive.
Preparing to unpack .../01-libarchive_3.3.3-1_aarch64.deb ...
Unpacking libarchive (3.3.3-1) ...
Selecting previously unselected package libexpat.
Preparing to unpack .../02-libexpat_2.2.6_aarch64.deb ...
Unpacking libexpat (2.2.6) ...
Selecting previously unselected package jsoncpp.
Preparing to unpack .../03-jsoncpp_1.8.4-2_aarch64.deb ...
Unpacking jsoncpp (1.8.4-2) ...
Selecting previously unselected package libuv.
Preparing to unpack .../04-libuv_1.26.0_aarch64.deb ...
Unpacking libuv (1.26.0) ...
Selecting previously unselected package rhash.
Preparing to unpack .../05-rhash_1.3.8_aarch64.deb ...
Unpacking rhash (1.3.8) ...
Selecting previously unselected package make.
Preparing to unpack .../06-make_4.2.1-2_aarch64.deb ...
Unpacking make (4.2.1-2) ...
Selecting previously unselected package cmake.
Preparing to unpack .../07-cmake_3.13.4-1_aarch64.deb ...
Unpacking cmake (3.13.4-1) ...
Selecting previously unselected package pcre.
Preparing to unpack .../08-pcre_8.43_aarch64.deb ...
Unpacking pcre (8.43) ...
Selecting previously unselected package glib.
Preparing to unpack .../09-glib_2.58.3-1_aarch64.deb ...
Unpacking glib (2.58.3-1) ...
Selecting previously unselected package libjpeg-turbo.
Preparing to unpack .../10-libjpeg-turbo_2.0.2_aarch64.deb ...
Unpacking libjpeg-turbo (2.0.2) ...
Selecting previously unselected package libjpeg-turbo-dev.
Preparing to unpack .../11-libjpeg-turbo-dev_2.0.2_aarch64.deb ...
Unpacking libjpeg-turbo-dev (2.0.2) ...
Selecting previously unselected package libpng.
Preparing to unpack .../12-libpng_1.6.36-1_aarch64.deb ...
Unpacking libpng (1.6.36-1) ...
Selecting previously unselected package libpng-dev.
Preparing to unpack .../13-libpng-dev_1.6.36-1_aarch64.deb ...
Unpacking libpng-dev (1.6.36-1) ...
Selecting previously unselected package pkg-config.
Preparing to unpack .../14-pkg-config_0.29.2_aarch64.deb ...
Unpacking pkg-config (0.29.2) ...
Setting up make (4.2.1-2) ...
Setting up jsoncpp (1.8.4-2) ...
Setting up libpng (1.6.36-1) ...
Setting up libexpat (2.2.6) ...
Setting up pcre (8.43) ...
Setting up glib (2.58.3-1) ...
Setting up libxml2 (2.9.9) ...
Setting up rhash (1.3.8) ...
Setting up pkg-config (0.29.2) ...
Setting up libpng-dev (1.6.36-1) ...
Setting up libjpeg-turbo (2.0.2) ...
Setting up libarchive (3.3.3-1) ...
Setting up libuv (1.26.0) ...
Setting up libjpeg-turbo-dev (2.0.2) ...
Setting up cmake (3.13.4-1) ...
Setting up ndk-sysroot (19b) ...
Setting up binutils (2.32-1) ...
Setting up libllvm (7.0.1-1) ...
Setting up clang (7.0.1-1) ...

Move into the desired folder

As I said in the previous step I did used the Termux setup storage and that is way this step might be different on your phone.

$ cd storage/shared/

Take into account that if you do not change the directory you might be working on $HOME directory which in Android is /data/data/com.termux/files/home

Create directory repository code will be

$ mkdir workspace

Go to the folder created

$ cd workspace/

Let's clone the code

$ git clone https://github.com/yeyeto2788/OpenNoteScannerPDF
Cloning into 'OpenNoteScannerPDF'...
remote: Enumerating objects: 60, done.
remote: Counting objects: 100% (60/60), done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 284 (delta 19), reused 45 (delta 10), pack-reused 224
Receiving objects: 100% (284/284), 1.48 MiB | 2.39 MiB/s, done.
Resolving deltas: 100% (138/138), done.

$ cd OpenNoteScannerPDF/

Upgrade pip (Optional)

I did this in order to avoid problems but there should not be any problems if you use the default installed pip.

$ pip install --upgrade pip
Collecting pip
  Downloading
https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl
(1.4MB)
    100% |████████████████████████████████| 1.4MB 2.7MB/s
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.0.3

Install needed Python modules

$ pip install -r requirement.txt
Collecting reportlab==3.5.13 (from -r requirement.txt (line 1))
  Downloading
https://files.pythonhosted.org/packages/6d/b5/495011623878f1000a2bfa62fa54c3b491071f0c77062dcd1bd86e2b9764/reportlab-3.5.13.tar.gz
(2.8MB)
    100% |████████████████████████████████| 2.8MB 2.4MB/s
Collecting qrcode==6.1 (from -r requirement.txt (line 2))
  Downloading
https://files.pythonhosted.org/packages/42/87/4a3a77e59ab7493d64da1f69bf1c2e899a4cf81e51b2baa855e8cc8115be/qrcode-6.1-py2.py3-none-any.whl
Collecting Pillow==5.4.1 (from -r requirement.txt (line 3))
  Downloading
https://files.pythonhosted.org/packages/3c/7e/443be24431324bd34d22dd9d11cc845d995bcd3b500676bcf23142756975/Pillow-5.4.1.tar.gz
(16.0MB)
    100% |████████████████████████████████| 16.0MB 640kB/s
Collecting Flask>=1.0.2 (from -r requirement.txt (line 4))
  Downloading
https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl
(91kB)
    100% |████████████████████████████████| 92kB 3.6MB/s
Collecting Flask-RESTful>=0.3.6 (from -r requirement.txt (line 5))
  Downloading
https://files.pythonhosted.org/packages/17/44/6e490150ee443ca81d5f88b61bb4bbb133d44d75b0b716ebe92489508da4/Flask_RESTful-0.3.7-py2.py3-none-any.whl
Collecting waitress>=1.2.1 (from -r requirement.txt (line 6))
  Downloading
https://files.pythonhosted.org/packages/b4/1e/3b51f5a9454a1f15ae5b82a7044e095c93eeefd2d1e5738e588fc43c9e89/waitress-1.2.1-py2.py3-none-any.whl
(140kB)
    100% |████████████████████████████████| 143kB 5.7MB/s
Collecting six (from qrcode==6.1->-r requirement.txt (line 2))
  Downloading
https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting itsdangerous>=0.24 (from Flask>=1.0.2->-r requirement.txt
(line 4))
  Downloading
https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Jinja2>=2.10 (from Flask>=1.0.2->-r requirement.txt (line 4))
  Downloading
https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
(126kB)
    100% |████████████████████████████████| 133kB 5.6MB/s
Collecting Werkzeug>=0.14 (from Flask>=1.0.2->-r requirement.txt (line
4))
  Downloading
https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
(322kB)
    100% |████████████████████████████████| 327kB 4.3MB/s
Collecting click>=5.1 (from Flask>=1.0.2->-r requirement.txt (line 4))
  Downloading
https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl
(81kB)
    100% |████████████████████████████████| 81kB 3.9MB/s
Collecting pytz (from Flask-RESTful>=0.3.6->-r requirement.txt (line 5))
  Downloading
https://files.pythonhosted.org/packages/61/28/1d3920e4d1d50b19bc5d24398a7cd85cc7b9a75a490570d5a30c57622d34/pytz-2018.9-py2.py3-none-any.whl
(510kB)
    100% |████████████████████████████████| 512kB 4.8MB/s
Collecting aniso8601>=0.82 (from Flask-RESTful>=0.3.6->-r requirement.txt
(line 5))
  Downloading
https://files.pythonhosted.org/packages/5d/0d/ca7f24d2f87163f03044315c13edc300010d898ba712c972f4a3a827a5ab/aniso8601-5.1.0-py2.py3-none-any.whl
(45kB)
    100% |████████████████████████████████| 51kB 4.9MB/s
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->Flask>=1.0.2->-r
requirement.txt (line 4))
  Downloading
https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
Collecting relativetimebuilder>=0.2.0 (from
aniso8601>=0.82->Flask-RESTful>=0.3.6->-r requirement.txt (line 5))
  Downloading
https://files.pythonhosted.org/packages/b9/46/fb188619006d458598d7a8910bbb5cd2c6debfb36821b460532bebddd046/relativetimebuilder-0.2.0-py2.py3-none-any.whl
Installing collected packages: pillow, reportlab, six, qrcode,
MarkupSafe, Jinja2, itsdangerous, Werkzeug, click, Flask, pytz,
relativetimebuilder, aniso8601, Flask-RESTful, waitress
  Running setup.py install for pillow ... done
  Running setup.py install for reportlab ... done
  Running setup.py install for MarkupSafe ... done
Successfully installed Flask-1.0.2 Flask-RESTful-0.3.7 Jinja2-2.10
MarkupSafe-1.1.1 Werkzeug-0.14.1 aniso8601-5.1.0 click-7.0
itsdangerous-1.1.0 pillow-5.4.1 pytz-2018.9 qrcode-6.1
relativetimebuilder-0.2.0 reportlab-3.5.13 six-1.12.0 waitress-1.2.1

Run the app

If you followed all the steps above, once you run the command below you should see the app on you phone and can you can access to it on 127.0.0.1:8080

$ python run_server.py
Serving on http://0.0.0.0:8080