question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: pyodide.runPythonAsync is not a function at PyButton.eval (base.ts:160:36)

See original GitHub issue

This works fine on one computer, but not another, both running chrome 101.

<py-button id="getscans" label="Load Scans">
    def on_click(evt):
        print('clicked!')
</button>

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
John-Schreibercommented, May 9, 2022

I found a way that works:

First, instead of using a py-button, I used a regular button, then added an onclick event handler with the DOM.

<button type="button" id="button_id">DoStuff</button>
button = document.getElementById("button_id")
button.addEventListener("click", DoStuff(args))

this caused my function be run with its arguments on script load, instead of onclick.

I had to wrap my python function in another python function, to create a python function that receives an [object PointerEvent], and calls DoStuff with my desired arguments. a simple button doesn’t need to parse the PointerEvent, so I ignore it.

def buttonwrapper(_):
    DoStuff(args)
    pass


button = document.getElementById("loadscans")
button.addEventListener("click", ButtonClickEvent)

That gave a different set of pyodide errors, which I was able to resolve with help from the pyodide docs.

Uncaught Error: This borrowed proxy was automatically destroyed at the end of a function call. Try using create_proxy or create_once_callable.
The object was of type "function" and had repr <function DoStuff at 0xdeadbeef>

adding create_proxy gives us a working button:

from js import document
from pyodide import create_proxy


def buttonwrapper(_):
    DoStuff(args)
    pass


ButtonClickEvent = create_proxy(buttonwrapper)

button = document.getElementById("loadscans")
button.addEventListener("click", ButtonClickEvent) 

I’m sure there is a more idiomatic way to do this, but this works.

1reaction
John-Schreibercommented, May 4, 2022

Your example has the same error with the same line numbers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pyodide runPythonAsync to html document - Stack Overflow
Basically, you can implement your own function for printing. However, if you want to use exactly print you can override the function from...
Read more >
runPythonAsync causes Python exception: AttributeError ...
I have been using pyodide in a project and calling pyodide.runPythonAsync with great success (Great Success!) but recently (the last few ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found