Open buybuyxyz opened 4 years ago
i have same problem..but where is your ..error log?
i think problem is mpmath there is no mpmath recipe
Yes, I think this is a bug too.
It occurs because the sympy recipe correctly specifies depends = ['mpmath']
In recipe.py depends
is defined as:
depends = []
'''A list containing the names of any recipes that this recipe depends on.
'''
However mpmath
does not have a recipe because it is pure Python, so the depends
is ignored and mpmath
is not scheduled to be installed in the app till after sympy
. The synpy
build then fails because mpmath
is not yet installed.
python_depends
does not address the issue
python_depends = []
'''A list of pure-Python packages that this package requires. These
packages will NOT be available at build time, but will be added to the
list of pure-Python packages to install via pip. If you need these packages
at build time, you must create a recipe.'''
From the outside this looks like a dependency graph error, with its roots in the definition of depends. I'd suggest 'or pure Python module' be appended, but one could imagine an mpmath
recipe as a solution (see below)
The issue arises in this case because sympy
is pure Python, but it needs a recipe because it's Python code has to be patched. But the issue is clearly more general than this one case.
To replicate:
from kivy.app import App
from kivy.uix.label import Label
from sympy import Symbol, integrate
class MyApp(App):
def build(self):
x = Symbol('x')
return Label(text=str(integrate(1/x,x)))
MyApp().run()
And the buildozer.spec as default except:
requirements = python3,kivy,mpmath,sympy
I tried the obvious work around:
# File: p4a-recipes/mpmath/__init__.py
# buildozer.spec: p4a.local_recipes = p4a-recipes
from pythonforandroid.recipe import PythonRecipe
class MpmathRecipe(PythonRecipe):
url = 'https://github.com/fredrik-johansson/mpmath/archive/master.zip'
depends = ['setuptools']
recipe = MpmathRecipe()
But this fails with ModuleNotFoundError: No module named 'setuptools'
Which appears to be #2078
I think I solved a similar problem by adding
call_hostpython_via_targetpython = False
install_in_hostpython = True
Thank you, that fixed the mpmath
build issue. It now builds before sympy
which was my diagnosis of the issue.
But........
I get back to the error message I had previously:
#Please install the mpmath package with a version >= 0.19
It turns out sympy
setup.py
line 54 is import mpmath
Adding a print shows this fails with No module named 'mpmath'
Regardless of mpmath
being installed before or after sympy
, or even mpmath
being installed on the executing machine. Which explains why my diagnosis was incorrect.
But leaves me completely confused at to how that import
works and the sympy
recipe ever worked, or how it passes regression tests.
Have you tried modifying the sympy
recipe to set call_hostpython_via_targetpython = False
?
But leaves me completely confused at to how that
import
works and thesympy
recipe ever worked, or how it passes regression tests.
It's included in BROKEN_RECIPES_PYTHON3
, so I don't think it passes any tests.
HaHa, TeeHee, HoHo, gasp, Haaaa. This is funny.
It seems as some zen monk might say, the best recipe is no recipe at all.
The solution for me was to copy the sympy
source to the project directory.
And set requirements = python3,kivy,mpmath
I added boolean and unicode expressions to the test case and everything worked on Android the same as on the desktop.
from kivy.app import App
from kivy.uix.label import Label
from sympy import Symbol, integrate, Integral,sqrt
from sympy.logic.boolalg import Or
class MyApp(App):
def build(self):
x = Symbol('x')
y = Symbol('y')
return Label(text=u"{}\n{}\n{}".format(integrate(1/x,x),
Integral(sqrt(1/x),x),
Or(x,y)))
MyApp().run()
All the synpy
recipe does is patch some unicode symbols to ASCII, but Kivy ignores these unicode symbols and just prints the equivalent ASCII expression (as shown in the example above, and despite using a unicode string) - so the patch appears redundant.
A couple of things I don't understand (can anybody enlighten me? , I'm using p4a.branch=develop):
1) why I had to copy the source, it seems to me p4a can easily find sympy
and since this is not listed in requirements I would expect p4a to get the source with pip. Perhaps this is because there exists a recipe I'm not using?
2) why I had to specify mpmath
, sympy/__init__.py
contains import mpmath
inside a try
, it seems p4a should find that.
I conclude from this the best thing to do is delete the synpy
recipe (and then the pip package will be downloaded, though it might have to be specified in requirements).
EDIT: But perhaps there will still be an issue with mpmath
in setup.py
, in which case the recipe would have to patch that and set python_depends = ['mpmath']
HaHa
All the
synpy
recipe does is patch some unicode symbols to ASCII, but Kivy ignores these unicode symbols and just prints the equivalent ASCII expression (as shown in the example above, and despite using a unicode string) - so the patch appears redundant.
I don't think you've used sympy
in a way that it would have produced unicode symbols in your example.
Why I had to copy the source, it seems to me p4a can easily find
sympy
and since this is not listed in requirements I would expect p4a to get the source with pip. Perhaps this is because there exists a recipe I'm not using?
AFAIK p4a only gets dependencies via pip if there is no recipe. So that is indeed the problem. You could try forking p4a and deleting the sympy
recipe to confirm this.
Why I had to specify
mpmath
,sympy/__init__.py
containsimport mpmath
inside atry
, it seems p4a should find that.
Dependency information does not come from import
statements; it is provided by recipes or pypi/pip packages.
Also: "unicode strings" only exist in Python 2, u"..."
produces a "normal" string in Python 3.
I don't think the current pretty printing patch makes much sense. It replaces e.g. ∧
with the text LOGICAL AND
.
I think it makes more sense to completely disable unicode for pretty printing. And it looks like the unicode detection in sympy
should already work correctly (since sys.stdout.encoding
is None
with p4a).
Unless I missed something, removing the sympy
recipe seems like the best solution.
I don't think the current pretty printing patch makes much sense. It replaces e.g. ∧ with the text LOGICAL AND.
Agreed, and your example currently prints the ASCII '&' which IMHO is better than either of the above. I can come up with a test case that is functional but less elegant, but the behavior is the same as Kivy on Windows. So to try to finesse it on Android would be inconsistent.
You could try forking p4a and deleting the
sympy
recipe to confirm this.
Cloned p4a , set p4a.source_dir = clone_dir
, and deleted clone's sympy
recipe and sympy
directory in app left over from previous test.
requirements = python3,kivy,sympy,mpmath
working 1 location(s) to search for versions of mpmath:
working: * https://pypi.org/simple/mpmath/
working: 1 location(s) to search for versions of sympy:
working: * https://pypi.org/simple/sympy/
Confirmed, this builds using sympy
and mpmath
using pip source, and runs the test case from my previous post.
I do wonder if this builds because mpmath
is alphabetically sorted before sympy
? But I've convinced myself I don't have to worry about that ;) I also uninstalled a local pip copy of mpmath
but, as expected, this did not change anything.
Unless I missed something, removing the sympy recipe seems like the best solution.
I agree. [Guaranteed we missed something ;) but the chances of somebody finding whatever it is look slim.]
is there any solution ...sympy for Android with Kivy ???
There are two different of work arounds in the posts above 1) Make a local copy of synpy and don't specify synpy in requirements https://github.com/kivy/python-for-android/issues/2303#issuecomment-689928162 2) Make a local copy of p4a, remove synpy, and specify synpy in requirements https://github.com/kivy/python-for-android/issues/2303#issuecomment-690811554
the solution is pretty simple just find and copy the mpmath folder to {.buildozer} where your working directory: copy the mpmath folder to those two places:
.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/sympy/armeabi-v7a__ndk_target_21/sympy/
and to this folder
.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/sympy/arm64-v8a__ndk_target_21/sympy/
I cannot add sympy when I build apk file with buildozer.
Checklist
p4a.branch = develop
)Versions
Description
// REPLACE ME: What are you trying to get done, what has happened, what went wrong, and what did you expect? I cannot add sympy when I build apk file with buildozer. Error
buildozer.spec
Command:
Spec file:
Logs