Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: dlopen failed: cannot locate symbol "_ZTVSt9bad_alloc" #2903

Closed
5 tasks
shixiangheng opened this issue Oct 22, 2023 · 12 comments
Closed
5 tasks

Comments

@shixiangheng
Copy link

Checklist

  • the issue is indeed a bug and not a support request
  • issue doesn't already exist: https://github.com/kivy/python-for-android/issues
  • I have a short, runnable example that reproduces the issue
  • I reproduced the problem with the latest development version (p4a.branch = develop)
  • I used the grave accent (aka backticks) to format code or logs when appropriated

Versions

  • Python: 3.11
  • OS: Android
  • Kivy:2.2.1
  • Cython:
  • OpenJDK:

Description

I have trouble importing matplotlib when running an app on my phone

buildozer.spec

Command:

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy==2.2.1,kivymd==1.1.1,pandas,peewee,appdirs,pytz,requests,dateutil,frozendict,multitasking,yfinance,matplotlib

Spec file:


Logs

Traceback (most recent call last):
2023-10-22 01:57:48.325 32749-616   python                  org.test.tqqqprediction              I     File "/mnt/c/App_Design/example2/.buildozer/android/app/main.py", line 15, in <module>
2023-10-22 01:57:48.325 32749-616   python                  org.test.tqqqprediction              I     File "/mnt/c/App_Design/example2/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/tqqqPrediction/arm64-v8a/matplotlib/__init__.py", line 109, in <module>
2023-10-22 01:57:48.325 32749-616   python                  org.test.tqqqprediction              I     File "/mnt/c/App_Design/example2/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/tqqqPrediction/arm64-v8a/matplotlib/rcsetup.py", line 27, in <module>
2023-10-22 01:57:48.325 32749-616   python                  org.test.tqqqprediction              I     File "/mnt/c/App_Design/example2/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/tqqqPrediction/arm64-v8a/matplotlib/colors.py", line 56, in <module>
2023-10-22 01:57:48.325 32749-616   python                  org.test.tqqqprediction              I     File "/mnt/c/App_Design/example2/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/tqqqPrediction/arm64-v8a/matplotlib/scale.py", line 23, in <module>
2023-10-22 01:57:48.325 32749-616   python                  org.test.tqqqprediction              I     File "/mnt/c/App_Design/example2/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/tqqqPrediction/arm64-v8a/matplotlib/ticker.py", line 136, in <module>
2023-10-22 01:57:48.325 32749-616   python                  org.test.tqqqprediction              I     File "/mnt/c/App_Design/example2/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/tqqqPrediction/arm64-v8a/matplotlib/transforms.py", line 46, in <module>
2023-10-22 01:57:48.326 32749-616   python                  org.test.tqqqprediction              I   ImportError: dlopen failed: cannot locate symbol "_ZTVSt9bad_alloc" referenced by "/data/data/org.test.tqqqprediction/files/app/_python_bundle/site-packages/matplotlib/_path.so"...
2023-10-22 01:57:48.326 32749-616   python                  org.test.tqqqprediction              I  Python for android ended.
@tcaduser
Copy link

This looks like it is the same issue as #2675. It looks like matplotlib needs to have need_stl_shared=True in its recipe, so that the c++ runtime library is installed.

@shixiangheng
Copy link
Author

This looks like it is the same issue as #2675. It looks like matplotlib needs to have need_stl_shared=True in its recipe, so that the c++ runtime library is installed.

Hi, thank you for your help! Could you specify which file I need to change? at what location?

@tcaduser
Copy link

If you are installed in a virtual environment, look in $VIRTUAL_ENV/lib/ for the pythonforandroid/recipes/matplotlib/__init__.py and put:

need_stl_shared=True

with the other global variables in the recipe class. If that fixes your problem, please consider making a pull request so others can benefit from it.

@tcaduser
Copy link

Actually my suggestion might not work at all, since matplotlib is a C++ recipe, and it should be including the library already

@RobertFlatt
Copy link
Contributor

Read the last paragraph here https://github.com/Android-for-Python/Android-for-Python-Users#install

The error reported is (failing to report) a memory usage error.
While what looks like an NDK limitation "should" not happen, the real issue may be memory usage.
Look for Python variables storing C memory references being garbage collected.
If in doubt use Python class variables not local variables.

@shixiangheng
Copy link
Author

If you are installed in a virtual environment, look in $VIRTUAL_ENV/lib/ for the pythonforandroid/recipes/matplotlib/__init__.py and put:

need_stl_shared=True

with the other global variables in the recipe class. If that fixes your problem, please consider making a pull request so others can benefit from it.

Yes, this one solved my problem I think. I changed the recipe.py file with "need_stl_shared=True". I also added this in the init.py file. I can see the canvas now after opening the app, so I believe the matplotlib dependency's problem is solved.

@josh140520
Copy link

were to write this need_stl_shared=True in init.py? just anywere?

@tcaduser
Copy link

this would be a class variable, not instance variable of one of the recipes. It is already implied by this line:

class MatplotlibRecipe(CppCompiledComponentsPythonRecipe):

Since it is derived from a class setting that variable:

need_stl_shared = True

So make sure if matplotlib is in your buildozer.spec, this should be taken care of. If you are not using matplotlib, then you need to find the package failing to set this flag.

@josh140520
Copy link

Thanks for the reply; it's well appreciated. Which branch do I need to use? I am currently using the 'develop' branch from my fork in Kivy.

@tcaduser
Copy link

if you are using matplotlib, this should all just work

@josh140520
Copy link

At some time and using other branches such as master, develop, release-2022.12.20 the Import error persist:

Traceback (most recent call last):
12-15 14:49:36.545 11502 11551 I python : File "/github/workspace/.buildozer/android/app/main.py", line 11, in
12-15 14:49:36.545 11502 11551 I python : File "/github/workspace/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/monitoring/armeabi-v7a/matplotlib/init.py", line 109, in
12-15 14:49:36.545 11502 11551 I python : File "/github/workspace/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/monitoring/armeabi-v7a/matplotlib/rcsetup.py", line 27, in
12-15 14:49:36.546 11502 11551 I python : File "/github/workspace/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/monitoring/armeabi-v7a/matplotlib/colors.py", line 56, in
12-15 14:49:36.546 11502 11551 I python : File "/github/workspace/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/monitoring/armeabi-v7a/matplotlib/scale.py", line 23, in
12-15 14:49:36.546 11502 11551 I python : File "/github/workspace/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/monitoring/armeabi-v7a/matplotlib/ticker.py", line 136, in
12-15 14:49:36.547 11502 11551 I python : File "/github/workspace/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/monitoring/armeabi-v7a/matplotlib/transforms.py", line 46, in
12-15 14:49:36.547 11502 11551 I python : ImportError: dlopen failed: cannot locate symbol "_ZTVSt9bad_alloc" referenced by "/data/data/org.test.monitoring/files/app/_python_bundle/site-packages/matplotlib/_path.so"...
12-15 14:49:36.547 11502 11551 I python : Python for android ended.
12-15 14:49:36.820 11581 11581 F DEBUG : #8 pc 0021fd90 /data/app/org.test.monitoring-n9GimRnyD2szl_r6noiH7Q==/lib/arm/libpython3.9.so (offset 0xb7000) (Py_InitializeFromConfig+940)

In my buildozer:

(list) Source files to include (let empty to include all the files)

source.include_exts = py,png,jpg,kv,atlas,mp3,db,xlsx

(list) Application requirements

requirements = python3==3.9.18,hostpython3==3.9.18,kivy,pillow==9.5.0,requests,flask,xlsxwriter,statistics,,kivy.garden,cython,pyparsing,pygments,matplotlib

change the major version of python used by the app

osx.python_version = 3.9.18

Kivy version to use

osx.kivy_version = 2.1.0

(str) python-for-android fork to use in case if p4a.url is not specified, defaults to upstream (kivy)

p4a.fork = josh140520

(str) python-for-android branch to use, defaults to master

p4a.branch = master

My fork for recipe.py: https://github.com/josh140520/python-for-android/blob/master/pythonforandroid/recipe.py

Initpy: https://github.com/josh140520/python-for-android/blob/master/pythonforandroid/recipes/matplotlib/__init__.py

The build is success, but the apk crash when I open in phone

@Julian-O
Copy link
Contributor

Please take this discussion to the support channels, not a closed bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants