< All posts

Jan. 26, 2020, 7:35 p.m.

Running my django project on my LineageOS (Android) with Termux

Termux is an Android terminal emulator and Linux environment application that works directly with no rooting or setup required. A minimal base system is installed automatically, additional packages are available using the APT package manager.

Steps

  1. Get Termux from https://termux.com/.

  2. Install Termux and install the necessary packages:

$ pkg update
$ pkg install libjpeg-turbo clang ndk-root libcrypt zlib python git
  1. Clone my project at Gitlab on your home directory
$ cd ~
$ git clone https://gitlab.com/
  1. Create virtualenv and Install my project dependencies
$ python -m venv myenv
$ source myenv/bin/activate
(myenv) $ export LDFLAGS='-L/data/data/com.termux/files/usr/lib/'
(myenv) $ export CFLAGS='-I/data/data/com.termux/files/usr/include/'
(myenv) $ python -m pip install -r requirements.txt

Sample output:

    Collecting Django==2.2.3 (from -r requirements.txt (line 1))
    Collecting django-filters==0.2.1 (from -r requirements.txt (line 2))
    Collecting django-tables2==2.0.6 (from -r requirements.txt (line 3))
    Collecting django-adminlte3==0.1.0 (from -r requirements.txt (line 4))
    Collecting django-crispy-forms==1.8.1 (from -r requirements.txt (line 5))
    Collecting django-multi-captcha-admin==1.0.0 (from -r requirements.txt (line 6))
    Collecting django-multiselectfield==0.1.8 (from -r requirements.txt (line 7))
    Collecting django-ranged-response==0.2.0 (from -r requirements.txt (line 8))
    Collecting sqlparse (from Django==2.2.3->-r requirements.txt (line 1))
    Collecting pytz (from Django==2.2.3->-r requirements.txt (line 1))
    Installing collected packages: sqlparse, pytz, Django, django-filters, django-tables2, django-adminlte3, django-crispy-forms, django-multi-captcha-admin, django-multiselectfield, django-ranged-response
    Running setup.py install for django-filters ... done
    Running setup.py install for django-multi-captcha-admin ... done
    Running setup.py install for django-multiselectfield ... done
    Running setup.py install for django-ranged-response ... done
    Successfully installed Django-2.2.3 django-adminlte3-0.1.0 django-crispy-forms-1.8.1 django-filters-0.2.1
    django-multi-captcha-admin-1.0.0 django-multiselectfield-0.1.8 django-ranged-response-0.2.0 django-tables2-2.0.6 pytz-2019.3 sqlparse-0.3.0
    Installing collected packages: Pillow, django-simple-captcha
    Running setup.py install for Pillow ... done
    Running setup.py install for django-simple-captcha ... done
    Successfully installed Pillow-7.0.0 django-simple-captcha-0.5.12
  1. Start the server and visit http://127.0.0.1:8000

(myenv) $ python3 manage.py runserver

Sample output:

    Watching for file changes with StatReloader
    Performing system checks...

    System check identified no issues (0 silenced).
    January 26, 2020 - 18:01:35
    Django version 2.2.3, using settings 'Project.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.
    [26/Jan/2020 18:01:56] "GET / HTTP/1.1" 302 0
    [26/Jan/2020 18:01:56] "GET /login?/login=/ HTTP/1.1" 301 0

References:
https://wiki.termux.com/wiki/Main_Page
https://wiki.termux.com/wiki/Python
https://github.com/python-pillow/Pillow/issues/1957