Kivy Buildozer - "No module named setuptools" after installing setuptools

1.3k Views Asked by At

I have a Flask server in a Python file. It's really simple:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello World!"

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

I'm using Kivy's Buildozer to build my file. After creating buildozer.spec and specifying requirements = kivy,flask I try to build with buildozer -v android debug which should build the APK.

Instead, it crashes in the middle of building and gives me this error:

File "setup.py", line 4, in

from setuptools import setup

ImportError: No module named setuptools

This setup.py is Buildozer's, not mine.

I uninstalled setuptools completely with sudo apt-get purge python-setuptools, sudo -H pip uninstall setuptools, and I removed the easy_install command from /usr/local/bin (both easy_install and easy_install-2.7). I run sudo easy_install and it says it's not there. Good.

Then I follow instructions from here, and I run wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python. It installs successfully, and I test that easy_install is there by doing sudo easy_install and checking at /usr/local/bin. I also go into the Python shell and type from setuptools import setup and it works. So, setuptools is installed. However, buildozer -v android debug still fails with the same error.

Could someone figure out what's happening? Setuptools is installed; why is Buildozer not finding it?

This is my log, with log_level = 2 in buildozer.spec: Link

3

There are 3 best solutions below

0
On BEST ANSWER

You are using the old python-for-android toolchain, which does not support a flask backend. Run buildozer android_new debug instead to use the new toolchain.

3
On

Try to figure out which python binary (environment) does the buildozer use. My guess that it uses another one then the one you think, and there setuptools isn't installed.

0
On

Although it is somewhat hacky, you can first call wget https://bootstrap.pypa.io/get-pip.py from your build script, then call python3 get-pip.py install, then python3 -m pip install setuptools. Just make sure that the python3 you are calling is the one that buildozer uses.

This part of my script looks something like this:

hostpython = sh.Command(self.hostpython_location)
os.system("wget https://bootstrap.pypa.io/get-pip.py")
shprint(hostpython, "get-pip.py", "install")
shprint(hostpython, "-m", "pip", "install", "setuptools")

Reference: a post about the get-pip script: How to get PIP for python