Buildozer requirements, the missing manual

295 views
Skip to first unread message

Robert Flatt

unread,
Nov 23, 2019, 8:46:29 PM11/23/19
to Kivy users support
It seems to me that the documentation of Buildozer "requirements" is totally correct but less than helpful.  It leads to a lot of guessing by users. The documentation says what one can do, not what one should do, or why. So this is my understanding about Buildozer's "requirements" option. If you have a short attention span this post is not for you ;)

In general Python for Android (Buildozer's engine) determines what external packages are referenced in an app. So you have do not have to add anything to the requirements order for the app import packages to "load" on Android without errors. However there are 3 special cases that Python for Android cannot determine.  In these cases the package must be specified in "requirements".

1) The package is not pure Python, and it has a Python for Android recipe. In this case specify the p4a recipe name in requirements. The list of recipes is here:  https://github.com/kivy/python-for-android/tree/develop/pythonforandroid/recipes

2) The package is pure Python, but the pip package name (as in: "pip install name") is not the same as the Python import name (as in .py : "import name"). In this case specify the pip package name in requirements. (see example below)

3) The package is pure Python, but the import statement in the Python code is somehow "hidden" by clever coding or other magic. In this case specify the pip package name in requirements.


So for example we always specify "python3, kivy" because these are examples of first case and we always use them in an app.

Failure to recognize any of these cases will result in an Android run time (logcat) error:      ModuleNotFoundError: No module named 'name'




Anybody know any other cases?


There are three corollaries to these cases.

A) If a package specified in requirements is not available to pip or not in the p4a recipes list then the Buildozer build will fail . If pip can't find the package the error message will be DistributionNotFound: No matching distribution found for name   (Python system packages are an example, don't specify these)

B) One can specify "pip available" pure Python packages in the "requirements" list that are not required by the three special cases, this does not hurt or help. At best these are duplicates and redundant, at worst the apk will be a little fatter than it needs to be

C) If the package is not pure Python and it is not in the p4a recipes list, then the task becomes harder than most people want to attempt. In part this seems to be due to lack of current documentation. Avoid disappointment, check if a package will load on Android before you start your project, this can be hard to research, building a small test case (see below) is the easiest way (and in the long run more informative than asking somebody here to do it for you).



Create your own test case like this one (replacing beautifulsoup4 ,bs4, and BeautifulSoup with whatever is your case):

The package Beautiful Soup is an example of case 2). The python code says "import bs4" but pip requires "pip install beautifulsoup4". Note that "beautifulsoup4" is not a package name in the Python code, the package name is "bs4". The object "BeautifulSoup" (no '4') is not relevant to requirements.

The example code below displays the number of symbols exported from the package (to show that the package has loaded), or crashes (to show the package didn't load!).

Without beautifulsoup4 in the requirements the app crashes with ModuleNotFoundError: No module named 'bs4'

In this case when the app runs on Windows the Label text shows 156, and on Android shows 150 (close enough).

requirements = python3,kivy,beautifulsoup4

from kivy.app import App
from kivy.uix.label import Label
from bs4 import BeautifulSoup


class Demo(App):
   
def build(self):
       
return Label(text=str(len(dir(BeautifulSoup))))

if __name__ == '__main__':
   
Demo().run()

Pablo Diaz

unread,
Nov 24, 2019, 9:30:55 PM11/24/19
to Kivy users support
Very useful information

טום ג

unread,
Nov 28, 2019, 1:11:36 AM11/28/19
to Kivy users support
Hi have another issue, htere is a bugged plyer version on github which i need on my buildozer compiled apk. I am able to fix the broken part of the librayry on my computer, however when i specify 'plyer' in the buildozer requirements line i am getting the broken one.
any ideas?

בתאריך יום שני, 25 בנובמבר 2019 בשעה 04:30:55 UTC+2, מאת Pablo Diaz:

Robert Flatt

unread,
Nov 28, 2019, 2:37:00 AM11/28/19
to Kivy users support
Plyer is pure Python (with wrapped  Java), right?
Copy the plyer you want to the project directory (same as main.py). Name the folder plyer. Don't specify plyer in requirements. It loads just as any user generated package.

Off the top of my head I don't know if p4a installs plyer by default, if it does I don't know what will happen in this case.

Robert Flatt

unread,
Nov 28, 2019, 2:55:47 AM11/28/19
to Kivy users support
Oh, wait this would be :

4) You want a specific version of a package.
   Add it to requirements as    package=="version"
Reply all
Reply to author
Forward
0 new messages