0

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

Community
  • 1
  • 1
Mingle Li
  • 1,322
  • 1
  • 15
  • 39
  • Post the full log. Buildozer is running its own python that it built (completely unrelated to your normal system python), but I'm not sure why you'd get a setuptools error from this - either it should not be necessary, or it should be installed by buildozer as a dependency. – inclement Jan 01 '17 at 01:03
  • @inclement Check new edit. – Mingle Li Jan 01 '17 at 15:15

3 Answers3

1

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.

inclement
  • 29,124
  • 4
  • 48
  • 60
0

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.

Sawel
  • 929
  • 7
  • 17
  • How would I figure out which binary it uses? What command should I use? – Mingle Li Jan 01 '17 at 00:32
  • You can try with strace.. Run: "strace buildozer android debug | grep python" and look for the path it uses to open python interpreter. – Sawel Jan 01 '17 at 00:34
  • Ah, I found it. It's `/usr/local/lib/python2.7/dist-packages/buildozer`, so Python 2.7. I installed Buildozer with `sudo python2.7 setup.py install` so it should be correct. – Mingle Li Jan 01 '17 at 00:39
0

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

Robert
  • 47
  • 6