Search code examples
pythoninstallationkivybuildozertinydb

How to install tinydb in App directory


I am creating an app using python and kivy using from tinydb import TinyD, Query to import the tinydb module. This works completely fine when testing my python and kivy code. After using buildozer to create an apk and debugging, it is saying that it crashed because of ImportError: no module named tinydb. I tried adding tinydb as a requiremenet in buildozer.spec, but that did not fix it. I'm fairly certain that I need to install tinydb in my App directory, this way the package is downloaded and included in my APK. However, I'm not quite sure how to do this. For example I installed the graph module from kivy garden using garden install --app graph. If anyone has any suggestions that would be great!


Solution

  • I've never used buildover but since tinydb is a tiny pure python library you could probably download and include the tinydb library directly in your project and import it locally.

    I used the following directory structure

    │   app.py
    ├───db
    │       db.json
    └───tinydb
        │   database.py
        │   middlewares.py
        │   operations.py
        │   queries.py
        │   storages.py
        │   utils.py
        │   __init__.py
    

    And main script app.py

    from tinydb import TinyDB, Query
    import os
    
    dirname = os.path.dirname(os.path.abspath(__file__))
    db = TinyDB(os.path.join(dirname, 'db', 'db.json'))