0

I'm trying to build app with Buildozer. In the main code im importing functools. The code runs Ok on computer, but when I try to run it on android I get NameError: name 'functools' is not defined

I tried to add it in buildozer.spec requirements, but that yields in different error:

File "/tmp/pip-install-ef316qvg/functools/functools.py", line 34
raise TypeError, 'compose expects at least one argument'
               ^
SyntaxError: invalid syntax
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Full log here

In the log I can see that buildozer is trying to install the functools but as far as I can tell it's already installed /usr/lib64/python3.7/functools.py and can be imported.

Could anyone please give me an idea whats going on?

EDIT: I took a look at functools verzion:

>>> from getversion import get_module_version
>>> import functools
>>> version, details = get_module_version(functools)
>>> print(version)
3.7.7.final.0
>>> print(details)
Version '3.7.7.final.0' found for module 'functools' by strategy 'get_builtin_module_version', after the following failed attempts:
 - Attempts for module 'functools':
   - <get_module_version_attr>: module 'functools' has no attribute '__version__'
   - <get_version_using_pkgresources>: Invalid version number: None
   - <get_builtin_module_version>: SUCCESS: 3.7.7.final.0
  • Looks like you are using an old Python version. – Klaus D. Jul 22 '20 at 13:47
  • Hi, thanks for comment. Could you be please more specific? – Tomáš Viks Pilný Jul 22 '20 at 13:53
  • Adding it to the `buildozer.spec` is causing it to try to install [this package](https://pypi.org/project/functools/), which isn't what you want - it's from 2005, and gives the error because it's using the old syntax for raising exceptions. I'm afraid I can't help with the original `NameError`. – Alasdair Jul 23 '20 at 08:56

2 Answers2

1

I think the version of python you have doesn't match with the code you've written. You've written the code which works in some other version but not the version you are working with.

  • That is possible, I'm trying to follow this topic https://stackoverflow.com/questions/47510030/how-to-handle-android-runtime-permission-with-kivy Could you please help me to get ti right? I don't know the differences between versions. EDIT: the problem is on line `return reduce(lambda a, b: a and b, [True if p == 0 else False for p in map(checkperm, permissions)])` – Tomáš Viks Pilný Jul 23 '20 at 09:00
  • I am not well acquainted with this but i would recommend you to update python and check the web for a similar program as well as the error. This will give you some insight on the problem you're facing. – Ayaan Singh Saundh Jul 23 '20 at 10:24
  • Please accept and upvote the answer if it helped you. – Ayaan Singh Saundh Jul 24 '20 at 06:26
1

With help of Ayaan I found the fix. As he mentioned I'm using Python 3, while trying to use code snippet designed for Python 2

The proper change is reduce() -> functools.reduce() and map() -> list(map())

return functools.reduce(lambda a, b: a and b,
    [True if p == 0 else False for p in list(map(checkperm, permissions))])