kivy / kivy/python-for-android
reportlab recipe not working with python3.9
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 2k
- Avg merge
- 12h 20m
- Merged PRs (30d)
- 9
Description
Hello,
I'm struggling to build my kivy project witch depends on `reportlab` on android.
I first tried to reference the recipe in my `buildozer.spec` file.
```
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy,numpy,reportlab
```
This compiles but gives the following error at runtime:
```
04-22 19:09:16.960 7698 7741 I python : Traceback (most recent call last):
04-22 19:09:16.961 7698 7741 I python : File "[path_to_project]/.buildozer/android/app/main.py", line 48, in
04-22 19:09:16.961 7698 7741 I python : File "[path_to_project]/.buildozer/android/app/pdfexport.py", line 1, in
04-22 19:09:16.961 7698 7741 I python : File "[path_to_project]/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/cargoready/arm64-v8a/reportlab/pdfgen/canvas.py", line 19, in
04-22 19:09:16.961 7698 7741 I python : File "[path_to_project]/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/cargoready/arm64-v8a/reportlab/rl_config.py", line 45, in
04-22 19:09:16.961 7698 7741 I python : File "[path_to_project]/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/cargoready/arm64-v8a/reportlab/rl_config.py", line 13, in _defaults_init
04-22 19:09:16.961 7698 7741 I python : File "[path_to_project]/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/reportlab/lib/utils.py", line 8, in
04-22 19:09:16.962 7698 7741 I python : ImportError: cannot import name 'decodestring' from 'base64' (/data/user/0/com.example.myapp/files/app/_python_bundle/stdlib.zip/base64.pyc)
04-22 19:09:16.962 7698 7741 I python : Python for android ended.
```
I googled and found [the same issue in another context](https://bugzilla.redhat.com/show_bug.cgi?id=1808508), it comes from an issue in reportlab: `base64.encodestring()` and `base64.decodestring()`, aliases are deprecated since Python 3.1, and have been removed, `base64.encodebytes()` and `base64.decodebytes()` should be used instead.
This issue has been fixed it the last `reportlab` versions.
However, the version is frozen in python-for-android recipe:
https://github.com/kivy/python-for-android/blob/56bf7335f08a51ec4e8427dd672e1b25a674026b/pythonforandroid/recipes/reportlab/__init__.py#L8-L10
I tried to update the version number in the local copy of python-for-android used by buildozer, but it doesn't work (`recipes/reportlab/patches/fix-setup.patch` no more applies to latest reportlab version).
I also tried to remove reportlab from buildozer.spec requirements, download reportlab source and copy it directly in my project's root, and this way it seems to work at compilation and runtime.
My last try was to remove reportlab from python-for-android recipes directory and include it in buildozer.spec requirements, so that it ends-up included as a pure python module.
It worked at compilation and runtime, except that I had to include also pillow in buildozer requirements, but it may be specific to my app's use of reportlab (it's an optional dependency if I remember well).
**So after all the solution appears to be removing reportlab recipe from python-for-android, but I'm new to python-for-android so not sure of the overall impact of removing it.**
I could make a PR.
Contributor guide
Research direction
Start with pythonforandroid/recipes/reportlab/__init__.py and recipes/reportlab/patches/fix-setup.patch, then compare the frozen ReportLab version with the version that supports Python 3.9. Reproduce the reportlab import failure through the buildozer.spec requirements. Done means the recipe builds and runs without requiring the recipe to be removed or ReportLab copied into the project manually.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, python
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100