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

Import Folium python package #74

Closed
PhilippeDou opened this issue Dec 16, 2018 · 11 comments
Closed

Import Folium python package #74

PhilippeDou opened this issue Dec 16, 2018 · 11 comments

Comments

@PhilippeDou
Copy link

I'll try to import Folium pakage, but I'have an error.
In build.gradle I have added install folium :
`android {
compileSdkVersion 26
defaultConfig {
applicationId "com.chaquo.python.hello"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
python {
// If Chaquopy fails to find Python on your build machine, enable the following
// line and edit it to point to a Python 3.4+ executable.
//buildPython "C:/Python37/python.exe"

        staticProxy "hello"
        extractPackages "Data"

        pip {
            // install "setuptools"
            install "folium"
        }`

I have an error when import folium is execute.
I have tried to add setuptools but I have an exception with pkg_ressouces.
If you have a solution ?

@mhsmith
Copy link
Member

mhsmith commented Dec 17, 2018

Please post the exception.

@PhilippeDou
Copy link
Author

If I take the Hello World project and I add :
pip { install "folium" }
inside build.gradle of App,
If I put in Hello.py :
from folium import Map
compilation is ok but the application crash when start
Sorry, I don't know how to catch the error.

@mhsmith
Copy link
Member

mhsmith commented Dec 17, 2018

You can probably find it in the Logcat window in Android Studio. Or if that fails, just take a screenshot.

@PhilippeDou
Copy link
Author

PhilippeDou commented Dec 17, 2018

Hereunder the content of the Logcat :

  --------- beginning of crash
2018-12-17 11:51:23.757 4912-4912/com.chaquo.python.hello E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.chaquo.python.hello, PID: 4912
    java.lang.ExceptionInInitializerError
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'pkg_resources'
        at <python>.java.chaquopy.import_override(import.pxi:18)
        at <python>.reraise(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/_vendor/six.py:686)
        at <python>.java.chaquopy.import_override(import.pxi:59)
        at <python>.<module>(/android_asset/chaquopy/requirements-common.zip/branca/utilities.py:20)
        at <python>.load_module_impl(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:391)
        at <python>.load_module(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:311)
        at <python>.java.chaquopy.import_override(import.pxi:18)
        at <python>.reraise(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/_vendor/six.py:686)
        at <python>.java.chaquopy.import_override(import.pxi:59)
        at <python>.<module>(/android_asset/chaquopy/requirements-common.zip/branca/element.py:20)
        at <python>.load_module_impl(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:391)
        at <python>.load_module(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:311)
        at <python>.java.chaquopy.import_override(import.pxi:18)
        at <python>.reraise(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/_vendor/six.py:686)
        at <python>.java.chaquopy.import_override(import.pxi:59)
        at <python>.<module>(/android_asset/chaquopy/requirements-common.zip/branca/colormap.py:14)
        at <python>.load_module_impl(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:391)
        at <python>.load_module(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:311)
        at <python>.java.chaquopy.import_override(import.pxi:18)
        at <python>.reraise(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/_vendor/six.py:686)
        at <python>.java.chaquopy.import_override(import.pxi:59)
        at <python>.<module>(/android_asset/chaquopy/requirements-common.zip/branca/__init__.py:5)
        at <python>.load_module_impl(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:391)
        at <python>.load_module(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:311)
        at <python>.java.chaquopy.import_override(import.pxi:18)
        at <python>.reraise(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/_vendor/six.py:686)
        at <python>.java.chaquopy.import_override(import.pxi:59)
        at <python>.<module>(/android_asset/chaquopy/requirements-common.zip/folium/__init__.py:8)
        at <python>.load_module_impl(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:391)
        at <python>.load_module(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:311)
        at <python>.java.chaquopy.import_override(import.pxi:18)
        at <python>.reraise(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/_vendor/six.py:686)
2018-12-17 11:51:23.758 4912-4912/com.chaquo.python.hello E/AndroidRuntime:     at <python>.java.chaquopy.import_override(import.pxi:59)
        at <python>.<module>(/android_asset/chaquopy/app.zip/hello.py:5)
        at <python>.load_module_impl(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:391)
        at <python>.load_module(/data/user/0/com.chaquo.python.hello/files/chaquopy/bootstrap.zip/java/android/importer.py:311)
        at <python>._load_backward_compatible(<frozen importlib._bootstrap>:626)
        at <python>._load_unlocked(<frozen importlib._bootstrap>:656)
        at <python>._find_and_load_unlocked(<frozen importlib._bootstrap>:955)
        at <python>._find_and_load(<frozen importlib._bootstrap>:971)
        at <python>._gcd_import(<frozen importlib._bootstrap>:994)
        at <python>.import_module(stdlib/importlib/__init__.py:126)
        at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModule(chaquopy_java.pyx:145)
        at com.chaquo.python.Python.getModule(Native Method)
        at hello.MainActivity.<clinit>(MainActivity.java:13)
        	... 12 more

@mhsmith
Copy link
Member

mhsmith commented Dec 17, 2018

OK, you were right to add setuptools, and here's the log after you do that:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "import.pxi", line 18, in java.chaquopy.import_override
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/bootstrap.zip/java/android/importer.py", line 331, in load_module
    self.load_module_impl()
  File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/bootstrap.zip/java/android/importer.py", line 411, in load_module_impl
    six.exec_(self.get_code(self.mod_name), mod.__dict__)
  File "/android_asset/chaquopy/requirements-common.zip/folium/__init__.py", line 8, in <module>
    import branca
  File "import.pxi", line 18, in java.chaquopy.import_override
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/bootstrap.zip/java/android/importer.py", line 331, in load_module
    self.load_module_impl()
  File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/bootstrap.zip/java/android/importer.py", line 411, in load_module_impl
    six.exec_(self.get_code(self.mod_name), mod.__dict__)
  File "/android_asset/chaquopy/requirements-common.zip/branca/__init__.py", line 5, in <module>
    import branca.colormap as colormap
  File "import.pxi", line 18, in java.chaquopy.import_override
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/bootstrap.zip/java/android/importer.py", line 331, in load_module
    self.load_module_impl()
  File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/bootstrap.zip/java/android/importer.py", line 411, in load_module_impl
    six.exec_(self.get_code(self.mod_name), mod.__dict__)
  File "/android_asset/chaquopy/requirements-common.zip/branca/colormap.py", line 72, in <module>
    class ColorMap(MacroElement):
  File "/android_asset/chaquopy/requirements-common.zip/branca/colormap.py", line 84, in ColorMap
    _template = ENV.get_template('color_scale.js')
  File "/android_asset/chaquopy/requirements-common.zip/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/android_asset/chaquopy/requirements-common.zip/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/android_asset/chaquopy/requirements-common.zip/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/android_asset/chaquopy/requirements-common.zip/jinja2/loaders.py", line 234, in get_source
    if not self.provider.has_resource(p):
  File "/android_asset/chaquopy/requirements-common.zip/pkg_resources/__init__.py", line 1402, in has_resource
    return self._has(self._fn(self.module_path, resource_name))
  File "/android_asset/chaquopy/requirements-common.zip/pkg_resources/__init__.py", line 1455, in _has
    "Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader type

I'll look into this and get back to you.

@mhsmith
Copy link
Member

mhsmith commented Dec 18, 2018

We'll fix this properly in the next version of Chaquopy. Meanwhile, try working around it by adding these lines before you import folium:

import pkg_resources
pkg_resources.NullProvider._has = lambda self, path: True

@PhilippeDou
Copy link
Author

Great
it works perfectly
Thank you

@PhilippeDou
Copy link
Author

I have another problem with folium.
Import function is ok, but when execute the main folium function I have an error :

coords = [48.8398094,2.5840685]
map = Map(location=coords, zoom_start=15)

can't perform this operation for unregistered loader type

I have submit this error to folium team, but they answer it's not a folium error.

@mhsmith
Copy link
Member

mhsmith commented Dec 20, 2018

OK, this will have to wait for the proper fix. We plan to release it within the next couple of weeks. Sorry for the inconvenience.

Exception:

File "/android_asset/chaquopy/requirements-common.zip/folium/raster_layers.py", line 115, in __init__
    filter_func=lambda x: x.startswith('tiles/')))
  File "/android_asset/chaquopy/requirements-common.zip/jinja2/environment.py", line 749, in list_templates
    x = self.loader.list_templates()
  File "/android_asset/chaquopy/requirements-common.zip/jinja2/loaders.py", line 265, in list_templates
    _walk(path)
  File "/android_asset/chaquopy/requirements-common.zip/jinja2/loaders.py", line 259, in _walk
    for filename in self.provider.resource_listdir(path):
  File "/android_asset/chaquopy/requirements-common.zip/pkg_resources/__init__.py", line 1423, in resource_listdir
    return self._listdir(self._fn(self.module_path, resource_name))
  File "/android_asset/chaquopy/requirements-common.zip/pkg_resources/__init__.py", line 1465, in _listdir
    "Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader type

@PhilippeDou
Copy link
Author

Ok thank you

@mhsmith
Copy link
Member

mhsmith commented Jan 19, 2019

Fixed in Chaquopy 5.1.2.

@mhsmith mhsmith closed this as completed Jan 19, 2019
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