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 - Matplotlib module #2059

Closed
mp-007 opened this issue Feb 5, 2020 · 2 comments
Closed

ImportError: dlopen failed: cannot locate symbol - Matplotlib module #2059

mp-007 opened this issue Feb 5, 2020 · 2 comments

Comments

@mp-007
Copy link
Contributor

mp-007 commented Feb 5, 2020

Versions
Python: Python-3.7.1
OS: Ubuntu 18.04 (Docker from buildozer's repo
https://github.com/kivy/buildozer/blob/master/Dockerfile ).
Kivy: 1.11.1
python-for-android: release-2019.08.09

Description
What are you trying to get done
Create an APK with a Python Kivy app which includes, numpy and matplotlib module.

What has happened and What went wrong
Building process finished correctly (I have the APK).
Execution process ended before the app is fully loaded with error message:
ImportError: dlopen failed: cannot locate symbol "_ZNSt12length_errorD1Ev" referenced by "/data/data/org.test.kivy_plot/files/app/_python_bundle/site-packages/matplotlib/_path.so"...

buildozer.spec

[app]

# (str) Title of your application
title = Kivy Matplotlib

# (str) Package name
package.name = kivy_plot

# (str) Package domain (needed for android/ios packaging)
package.domain = org.test

# (str) Source code where the main.py live
source.dir = .

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas

# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png

# (str) Application versioning (method 1)
version = 1.0.0

# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy,numpy,matplotlib

# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../kivy

# (list) Garden requirements
garden_requirements = matplotlib

# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png

# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png

# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
orientation = landscape

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 0

# (string) Presplash background color (for new android toolchain)
android.presplash_color = #FFFFFF

# (list) Permissions
android.permissions = INTERNET,WRITE_EXTERNAL_STORAGE

# (int) Target Android API, should be as high as possible.
#android.api = 28

# (int) Minimum API your APK will support.
#android.minapi = 21

# (str) Android NDK version to use
android.ndk = 19c

# (bool) If True, then skip trying to update the Android sdk
# This can be useful to avoid excess Internet downloads or save time
# when an update is due and you just want to test/build your package
android.skip_update = False

# (bool) If True, then automatically accept SDK license
# agreements. This is intended for automation only. If set to False,
# the default, you will be shown the license when first running
# buildozer.
android.accept_sdk_license = True

# (str) Android logcat filters to use
android.logcat_filters = *:S python:D

# (str) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
android.arch = armeabi-v7a


[buildozer]

# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2

# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 0

# (str) Path to build artifact storage, absolute or relative to spec file
build_dir = ./.buildozer

# (str) Path to build output (i.e. .apk, .ipa) storage
bin_dir = ./bin

main.py

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout

import numpy as np
import matplotlib.pyplot as plt
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvas


def enter_axes(event):
    print('enter_axes', event.inaxes)
    event.inaxes.patch.set_facecolor('yellow')
    event.canvas.draw()


def leave_axes(event):
    print('leave_axes', event.inaxes)
    event.inaxes.patch.set_facecolor('white')
    event.canvas.draw()


def enter_figure(event):
    print('enter_figure', event.canvas.figure)
    event.canvas.figure.patch.set_facecolor('red')
    event.canvas.draw()


def leave_figure(event):
    print('leave_figure', event.canvas.figure)
    event.canvas.figure.patch.set_facecolor('grey')
    event.canvas.draw()


kv = """
<Test>:
    orientation: 'vertical'
    Button:
        size_hint_y: None
        height: 40
"""

Builder.load_string(kv)


class Test(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(Test, self).__init__(*args, **kwargs)
        self.add_plot()

    def get_fc(self, i):
        fig1 = plt.figure()
        fig1.suptitle('mouse hover over figure or axes to trigger events' +
                      str(i))
        ax1 = fig1.add_subplot(211)
        ax2 = fig1.add_subplot(212)
        wid = FigureCanvas(fig1)
        fig1.canvas.mpl_connect('figure_enter_event', enter_figure)
        fig1.canvas.mpl_connect('figure_leave_event', leave_figure)
        fig1.canvas.mpl_connect('axes_enter_event', enter_axes)
        fig1.canvas.mpl_connect('axes_leave_event', leave_axes)
        return wid

    def add_plot(self):
        self.add_widget(self.get_fc(1))
        self.add_widget(self.get_fc(2))


class TestApp(App):
    def build(self):
        return Test()

if __name__ == '__main__':
    TestApp().run()

log

2020-02-05 11:15:49.499 27356-27387/org.test.kivy_plot I/python: Initialized python
2020-02-05 11:15:49.499 27356-27387/org.test.kivy_plot I/python: AND: Init threads
2020-02-05 11:15:49.515 27356-27387/org.test.kivy_plot I/python: testing python print redirection
2020-02-05 11:15:49.563 27356-27387/org.test.kivy_plot I/python: Android path ['.', '/data/user/0/org.test.kivy_plot/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.test.kivy_plot/files/app/_python_bundle/modules', '/data/user/0/org.test.kivy_plot/files/app/_python_bundle/site-packages']
2020-02-05 11:15:49.575 27356-27387/org.test.kivy_plot I/python: os.environ is environ({'PATH': '/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin', 'DOWNLOAD_CACHE': '/data/cache', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/bouncycastle.jar:/system/framework/apache-xml.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/android.hidl.base-V1.0-java.jar:/system/framework/android.hidl.manager-V1.0-java.jar:/system/framework/framework-oahl-backward-compatibility.jar:/system/framework/android.test.base.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/com.android.location.provider.jar', 'ANDROID_SOCKET_zygote': '11', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/org.test.kivy_plot/files/app', 'ANDROID_APP_PATH': '/data/user/0/org.test.kivy_plot/files/app', 'ANDROID_PRIVATE': '/data/user/0/org.test.kivy_plot/files', 'ANDROID_UNPACK': '/data/user/0/org.test.kivy_plot/files/app', 'PYTHONHOME': '/data/user/0/org.test.kivy_plot/files/app', 'PYTHONPATH': '/data/user/0/org.test.kivy_plot/files/app:/data/user/0/org.test.kivy_plot/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'True', 'P4A_ORIENTATION': 'landscape', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
2020-02-05 11:15:49.577 27356-27387/org.test.kivy_plot I/python: Android kivy bootstrap done. __name__ is __main__
2020-02-05 11:15:49.577 27356-27387/org.test.kivy_plot I/python: AND: Ran string
2020-02-05 11:15:49.577 27356-27387/org.test.kivy_plot I/python: Run user program, change dir and execute entrypoint
2020-02-05 11:15:50.091 27356-27387/org.test.kivy_plot I/python: [INFO   ] [Logger      ] Record log in /data/user/0/org.test.kivy_plot/files/app/.kivy/logs/kivy_20-02-05_6.txt
2020-02-05 11:15:50.093 27356-27387/org.test.kivy_plot I/python: [INFO   ] [Kivy        ] v1.11.1
2020-02-05 11:15:50.095 27356-27387/org.test.kivy_plot I/python: [INFO   ] [Kivy        ] Installed at "/data/user/0/org.test.kivy_plot/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
2020-02-05 11:15:50.098 27356-27387/org.test.kivy_plot I/python: [INFO   ] [Python      ] v3.7.1 (default, Feb  5 2020, 18:59:28) 
2020-02-05 11:15:50.099 27356-27387/org.test.kivy_plot I/python: [Clang 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec7462
2020-02-05 11:15:50.100 27356-27387/org.test.kivy_plot I/python: [INFO   ] [Python      ] Interpreter at "android_python"
2020-02-05 11:15:51.532 27356-27387/org.test.kivy_plot I/python: [INFO   ] [Factory     ] 184 symbols loaded
2020-02-05 11:15:52.492 27356-27387/org.test.kivy_plot I/python: [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
2020-02-05 11:15:53.385 27356-27387/org.test.kivy_plot I/python:  Traceback (most recent call last):
2020-02-05 11:15:53.387 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/app/main.py", line 6, in <module>
2020-02-05 11:15:53.393 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/kivy_plot/matplotlib/pyplot.py", line 32, in <module>
2020-02-05 11:15:53.397 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/kivy_plot/matplotlib/colorbar.py", line 28, in <module>
2020-02-05 11:15:53.398 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/kivy_plot/matplotlib/artist.py", line 11, in <module>
2020-02-05 11:15:53.401 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/kivy_plot/matplotlib/path.py", line 17, in <module>
2020-02-05 11:15:53.402 27356-27387/org.test.kivy_plot I/python:  ImportError: dlopen failed: cannot locate symbol "_ZNSt12length_errorD1Ev" referenced by "/data/data/org.test.kivy_plot/files/app/_python_bundle/site-packages/matplotlib/_path.so"...
2020-02-05 11:15:53.402 27356-27387/org.test.kivy_plot I/python: Python for android ended.
2020-02-05 11:15:53.403 27356-27387/org.test.kivy_plot E/ndk_translation: Unknown fcntl command: 1030
2020-02-05 11:15:53.405 27356-27387/org.test.kivy_plot I/python:  Error in atexit._run_exitfuncs:
2020-02-05 11:15:53.406 27356-27387/org.test.kivy_plot I/python:  Traceback (most recent call last):
2020-02-05 11:15:53.407 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/shutil.py", line 485, in rmtree
2020-02-05 11:15:53.409 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/shutil.py", line 404, in _rmtree_safe_fd
2020-02-05 11:15:53.411 27356-27387/org.test.kivy_plot I/python:    File "/home/kivy/Desktop/test_matplotlib2/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/shutil.py", line 400, in _rmtree_safe_fd
2020-02-05 11:15:53.412 27356-27387/org.test.kivy_plot I/python:  OSError: [Errno 38] Function not implemented: '/data/data/org.test.kivy_plot/files/app/matplotlib-izant70u'
2020-02-05 11:15:53.532 27356-27387/org.test.kivy_plot D/HostConnection: HostConnection::get() New Host Connection established 0xdf9267c0, tid 27387
2020-02-05 11:15:53.535 27356-27387/org.test.kivy_plot D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 

@mp-007
Copy link
Contributor Author

mp-007 commented Feb 5, 2020

I was able to solve my issue my changing the line 128 in the recipe.py by "need_stl_shared = True".
I'm sure it is not the best way, but I don't know how to change this feature in the matplotlib recipe.

Maybe someone can help me on this.

@KritikaVersha
Copy link

Has anyone been able to find a workaround for this? I have a similar error:

I/python:  ImportError: dlopen failed: cannot locate symbol "_ZTVSt9bad_alloc" referenced by "/data/data/org.d_unite.d_unite/files/app/_python_bundle/site-packages/matplotlib/_path.so"...
I/python: Python for android ended.

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

2 participants