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".
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()