1

i'm trying to make a simple code with pyScript and the folium library, but I'am continually getting this error

[pyscript/base] PythonError: Traceback (most recent call last):
  File "/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 506, in eval_code_async
    await CodeRunner(
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 357, in run_async
    coroutine = eval(self.code, globals, locals)
  File "<exec>", line 3, in <module>
TypeError: 'module' object is not callable

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script defer src="https://pyscript.net/latest/pyscript.js"></script>
    <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
   
    <py-env>
        - folium
    </py-env>
   
    <title>pyscipt test</title>
</head>
<body>
    <div id="map" style="width: 100%; height: 100%"></div>

    <py-script output="map">
import folium as fpl

m = fpl.map(location=[-6.2238, 106.8193], zoom_start=10)

print(m)
    </py-script>
</body>
</html>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Manel
  • 13
  • 4
  • 1
    Do the Folium examples work for you? Start there & then build in your changes. I say this because your code already seem outdated. See [here](https://stackoverflow.com/a/74131753/8508004) about `` which you use being deprecated in favor of `` which the official Folium example [here](https://pyscript.net/examples/folium.html) uses. This [comment here](https://stackoverflow.com/a/74131494/8508004): "As it develops, some things in PyScript are moving targets", & the closing statement at the bottom may give you a sense things are changing rapidly. – Wayne Oct 20 '22 at 15:37
  • 1
    I think `fpl.map(...)` should be `fpl.Map(...)`? – John Hanley Oct 23 '22 at 03:38

1 Answers1

0

Your code needs some update and corrections. Try this modified code.

    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script defer src="https://pyscript.net/latest/pyscript.js"></script>
        <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
       
    <py-config>
packages = [
  "folium",
]
    </py-config>
       
        <title>pyscript test: Success!</title>
    </head>
    <body>
        <div id="map" style="width: 100%; height: 100%"></div>

        <py-script output="map">
    import folium as fpl

    m = fpl.Map(location=[-6.2238, 106.8193], zoom_start=10)
    fpl.LayerControl().add_to(m)
    m
        </py-script>
    </body>
    </html>

Some warning from pyscript site:-

Please be advised that PyScript is very alpha and under heavy development. There are many known issues, from usability to loading times, and you should expect things to change often. We encourage people to play and explore with PyScript, but at this time we do not recommend using it for production.

swatchai
  • 17,400
  • 3
  • 39
  • 58