AttributeError in PyScript when using Panel

280 views Asked by At

I am running Python via Pyscript and my code used to work fine for around 1 year. However its no longer working and I get the following error message

JsException(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 500, 
  in eval_code_async await CodeRunner( 
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 353, 
  in run_async await coroutine File "", line 2, in 
File "/lib/python3.10/site-packages/panel/__init__.py", line 48, 
  in from . import layout # noqa 
File "/lib/python3.10/site-packages/panel/layout/__init__.py", line 31, 
  in from .accordion import Accordion # noqa 
File "/lib/python3.10/site-packages/panel/layout/accordion.py", line 5, 
  in from .base import NamedListPanel 
File "/lib/python3.10/site-packages/panel/layout/base.py", line 13, 
  in from ..reactive import Reactive 
File "/lib/python3.10/site-packages/panel/reactive.py", line 33, 
  in from .viewable import Layoutable, Renderable, Viewable 
File "/lib/python3.10/site-packages/panel/viewable.py", line 25, 
  in from .config import config, panel_extension 
File "/lib/python3.10/site-packages/panel/config.py", line 417, 
  in config = _config(**{k: None if p.allow_None else getattr(_config, k) 
File "/lib/python3.10/site-packages/panel/config.py", line 216, 
  in __init__ super().__init__(**params) 
File "/lib/python3.10/site-packages/param/parameterized.py", line 4139, 
  in __init__ if not isinstance(self._param__private, _InstancePrivate): 
File "/lib/python3.10/site-packages/panel/config.py", line 289, 
  in __getattribute__ init = super().__getattribute__('initialized') AttributeError: '_config' object has no attribute 'initialized' )"

I don't know how to fix it so Ive not tried anything yet.

My Code is below:

<html>

<head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://unpkg.com/@holoviz/[email protected]/dist/bundled/bootstraptemplate/bootstrap.css">

    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vega@5"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vega-lite@5"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
    <script type="text/javascript" src="https://unpkg.com/[email protected]/dist/js/tabulator.js"></script>
    <script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.js"></script>
    <script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js"></script>
    <script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js"></script>
    <script type="text/javascript" src="https://unpkg.com/@holoviz/[email protected]/dist/panel.min.js"></script>
    <script type="text/javascript">
      Bokeh.set_log_level("info");
    </script>

    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    <py-env>
        - numpy
        - pandas
        - panel==0.13.1a2
        - xlsxwriter
        - openpyxl

    </py-env>
</head>

<body>
    <div class="container-fluid d-flex flex-column vh-100 overflow-hidden" id="container">
        <nav class="navbar navbar-expand-md navbar-dark sticky-top shadow" id="header"
            style="background-color: #0f54ea;">
            <div class="app-header">
                <a class="title" href="" style="color: #f7f6f3;"> Calcuator</a>
            </div>
        </nav>

        <div class="row overflow-hidden" id="content">
            <div class="col mh-100 float-left" id="main">
                <p> Please Upload a CSV file below to start the  calculation! </p>
                <div id="fileinput"></div>
                <div id="table"></div>
                <div id="download"></div>
            </div>
        </div>
    </div>
<py-script>
import asyncio
import panel as pn

import pandas as pd
from panel.io.pyodide import show
import xlsxwriter
import openpyxl

file_input = pn.widgets.FileInput(accept='.xlsx', width=180)
button_upload = pn.widgets.Button(name='Upload', button_type='primary', width=100)
row = pn.Row(file_input, button_upload, height=75)

table = pn.widgets.Tabulator(pagination='remote', page_size=20, disabled=True)
document.getElementById('table').style.display = 'none'


await show(row, 'fileinput')
await show(table, 'table')
await show(file_download_csv, 'download')

print(row)
print(table)
print(file_download_csv)

document.getElementById('download').style.display = 'none'

</py-script>
</body>

</html>

UPDATE:

I updated the PyScript to the latest one: https://pyscript.net/latest/pyscript.js

And Now I get a different Error, the error is:

UserError: (PY9000): The use of top-level "await", "async for", and "async with" has been removed.
Please write a coroutine containing your code and schedule it using asyncio.ensure_future() or similar.
See https://docs.pyscript.net/latest/guides/asyncio.html for more information.

I think this error is more specific however, I have no idea what a coroutine is, any help will be highly appreciated.

UPDATE 2:

I created a coroutine and I got a error saying

No module named 'panel'

So to conclude I created this script when PyScript was in its Beta stage, and the code samples Ive used to create the script have been updated. So I will be recreating the script with the new code examples provided and hopefully fix the issue.

1

There are 1 answers

0
Mikhail Rubinov On

I solve this by installing package 'param' of version 1.13.0 after installing panel. Seems 'param' package broke something

pip install param==1.13.0