I am working on a Kivy project for Android, and I am making my own recipe. When I run buildozer android debug in WSL (Ubuntu), I get the following error complaining that setuptools is not installed:
Exception in thread background thread for pid 4936:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/home/robert/homework/mpdfereader/venv/lib/python3.10/site-packages/sh.py", line 1641, in wrap
fn(*rgs, **kwargs)
File "/home/robert/homework/mpdfereader/venv/lib/python3.10/site-packages/sh.py", line 2569, in background_thread
handle_exit_code(exit_code)
File "/home/robert/homework/mpdfereader/venv/lib/python3.10/site-packages/sh.py", line 2269, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/robert/homework/mpdfereader/venv/lib/python3.10/site-packages/sh.py", line 869, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /home/robert/homework/mpdfereader/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py build
STDOUT:
Traceback (most recent call last):
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/PyMuPDF/armeabi-v7a__ndk_target_21/PyMuPDF/setup.py", line 111, in <module>
from setuptools import Extension, setup
ModuleNotFoundError: No module named 'setuptools'
STDERR:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1312, in <module>
main()
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
ToolchainCL()
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 734, in __init__
getattr(self, command)(args)
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 153, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 212, in build_dist_from_args
build_recipes(build_order, python_modules, ctx,
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 504, in build_recipes
recipe.build_arch(arch)
File "/home/robert/homework/mpdfereader/recipes/PyMuPDF/__init__.py", line 21, in build_arch
shprint(hostpython, "setup.py", "build")
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
for line in output:
File "/home/robert/homework/mpdfereader/venv/lib/python3.10/site-packages/sh.py", line 915, in next
self.wait()
File "/home/robert/homework/mpdfereader/venv/lib/python3.10/site-packages/sh.py", line 845, in wait
self.handle_command_exit_code(exit_code)
File "/home/robert/homework/mpdfereader/venv/lib/python3.10/site-packages/sh.py", line 869, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /home/robert/homework/mpdfereader/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py build
STDOUT:
Traceback (most recent call last):
File "/home/robert/homework/mpdfereader/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/PyMuPDF/armeabi-v7a__ndk_target_21/PyMuPDF/setup.py", line 111, in <module>
from setuptools import Extension, setup
ModuleNotFoundError: No module named 'setuptools'
STDERR:
# Command failed: ['/home/robert/homework/mpdfereader/venv/bin/python', '-m', 'pythonforandroid.toolchain', 'create', '--dist_name=pdfreader', '--bootstrap=sdl2', '--requirements=python3,kivy,plyer,setuptools,PyMuPDF,frontend,starlette,anyio,sniffio,uvicorn,click,itsdangerous', '--arch=arm64-v8a', '--arch=armeabi-v7a', '--copy-libs', '--local-recipes', '/home/robert/homework/mpdfereader/recipes', '--color=always', '--storage-dir=/home/robert/homework/mpdfereader/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a', '--ndk-api=21', '--ignore-setup-py', '--debug']
# ENVIRONMENT:
# SHELL = '/bin/bash'
# WSL2_GUI_APPS_ENABLED = '1'
# WSL_DISTRO_NAME = 'Ubuntu-20.04'
# NAME = 'DESKTOP-NFE1G8T'
# PWD = '/home/robert/homework/mpdfereader'
# LOGNAME = 'robert'
# MOTD_SHOWN = 'update-motd'
# HOME = '/home/robert'
# LANG = 'C.UTF-8'
# WSL_INTEROP = '/run/WSL/8_interop'
# LS_COLORS = 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'
# VIRTUAL_ENV = '/home/robert/homework/mpdfereader/venv'
# WAYLAND_DISPLAY = 'wayland-0'
# LESSCLOSE = '/usr/bin/lesspipe %s %s'
# TERM = 'xterm-256color'
# LESSOPEN = '| /usr/bin/lesspipe %s'
# USER = 'robert'
# DISPLAY = ':0'
# SHLVL = '1'
# XDG_RUNTIME_DIR = '/mnt/wslg/runtime-dir'
# PS1 = ('(venv) \\[\\e]0;\\u@\\h: '
'\\w\\a\\]${debian_chroot:+($debian_chroot)}\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ ')
# WSLENV = ''
# XDG_DATA_DIRS = '/usr/local/share:/usr/share:/var/lib/snapd/desktop'
# PATH = ('/home/robert/.buildozer/android/platform/apache-ant-1.9.4/bin:/home/robert/homework/mpdfereader/venv/bin:/home/robert/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program '
'Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2022.8.0_x64__79rhkp1fndgsc:/mnt/c/Python311/Scripts/:/mnt/c/Python311/:/mnt/c/Program '
'Files/Common '
'Files/Oracle/Java/javapath:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program '
'Files/MATLAB/R2023a/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files '
'(x86)/Notepad++/:/mnt/c/Program '
'Files/nodejs/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program '
'Files/Calibre2/:/mnt/c/Users/rketl/AppData/Local/Microsoft/WindowsApps:/mnt/c/Program '
'Files/JetBrains/IntelliJ IDEA Community Edition '
'2022.2.2/bin:/mnt/c/Users/rketl/AppData/Local/Programs/Microsoft VS '
'Code/bin:/mnt/c/Program Files/JetBrains/PyCharm Community Edition '
'2022.3.1/bin:/mnt/c/Users/rketl/AppData/Roaming/npm:/snap/bin:/home/robert/.local/bin/')
# HOSTTYPE = 'x86_64'
# PULSE_SERVER = 'unix:/mnt/wslg/PulseServer'
# OLDPWD = '/home/robert'
# _ = '/home/robert/homework/mpdfereader/venv/bin/buildozer'
# PACKAGES_PATH = '/home/robert/.buildozer/android/packages'
# ANDROIDSDK = '/home/robert/.buildozer/android/platform/android-sdk'
# ANDROIDNDK = '/home/robert/.buildozer/android/platform/android-ndk-r25b'
# ANDROIDAPI = '31'
# ANDROIDMINAPI = '21'
#
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2
I have the following packages installed in a virtual environment, which is activated when I run the buildozer android debug command:
appdirs==1.4.4
buildozer==1.5.0
certifi==2023.5.7
charset-normalizer==3.1.0
colorama==0.4.6
Cython==0.29.35
distlib==0.3.6
docutils==0.20.1
filelock==3.12.2
idna==3.4
Jinja2==3.1.2
Kivy==2.2.1
Kivy-Garden==0.1.5
MarkupSafe==2.1.3
numpy==1.25.0
packaging==23.1
pep517==0.13.0
pexpect==4.8.0
platformdirs==3.8.0
plyer==2.1.0
ptyprocess==0.7.0
Pygments==2.15.1
PyMuPDF==1.22.5
requests==2.31.0
sh==1.14.3
toml==0.10.2
tomli==2.0.1
urllib3==2.0.3
virtualenv==20.23.1
The package for which I am trying to make a recipe is PyMuPDF, I know that this package will not actually properly install the mupdf library, but I am just trying to get it to build for now, I will get to that issue later. The file __init__.py can be found in ./recipes/PyMuPDF/, and contains the following:
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from pythonforandroid.toolchain import current_directory
from pythonforandroid.toolchain import shprint
import sh
import shutil
class PyMuPDFRecipe(CompiledComponentsPythonRecipe):
version = '1.22.5'
url = 'https://github.com/pymupdf/PyMuPDF/archive/refs/tags/{version}.tar.gz'
site_packages_name = "PyMuPDF"
depends = []
patches = []
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
env = super().get_recipe_env(arch, with_flags_in_cc)
return env
def build_arch(self, arch):
with current_directory(self.get_build_dir(arch.arch)):
hostpython = sh.Command(self.hostpython_location)
shprint(hostpython, "setup.py", "build")
# shutil.copyfile('a_generated_binary.so', self.ctx.get_libs_dir(arch.arch))
When I run pip install setuptools with my venv activated, I get the message saying it is already installed:
Requirement already satisfied: setuptools in ./venv/lib/python3.10/site-packages (67.8.0)
I also try to run pip install setuptools without my venv activated, in the WSL, and I get
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (59.6.0)
Running sudo pip install setuptools:
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (59.6.0)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Here are my buildozer.spec requirements and recipe folder lines:
requirements = python3,kivy,plyer,setuptools,PyMuPDF,frontend,starlette,anyio,sniffio,uvicorn,click,itsdangerous
p4a.local_recipes = ./recipes/
In conclusion: I have one question for now: How do I make buildozer properly find setuptools, and start my PyMuPDF build? Thanks!