I have been using Pyodide to run some python in my website. It has been working up until recently, however now has begin giving this error,
Uncaught ReferenceError: languagePluginLoader is not defined
at 2347:162
Some searching has revealed that this method is deprecated in pyodide anyway
https://pyodide.org/en/stable/usage/api/js-api.html#globalThis.loadPyodide
and Insteasd of using languagePluginUrl I should use loadPyodide.
I have no idea how to do this, I know nothing of js, only python,
My code is...
<script type="text/javascript">
languagePluginLoader.then(() => {
pyodide.loadPackage(['numpy']).then(() => {
pyodide.runPython(`
# My python code here
`);
});});
</script>
This used to work fine, so I think I just need to use the new method. Any help converting it to the new method appreciated - Thanks.
You're probably using a newer version of pyodide. Since 0.18.0, you should use loadPyodide
with the pyodide base url instead, which gives the pyodide
object in the callback:
const PYODIDE_BASE_URL = "https://cdn.jsdelivr.net/pyodide/v0.18.0/full"
loadPyodide({ indexURL: PYODIDE_BASE_URL }).then((pyodide) => {
globalThis.pyodide = pyodide // you might also want to store pyodide globally so
// so you can access anywhere in the scope
pyodide.loadPackage(['numpy']).then(() => {
pyodide.runPython(`
# My python code here
`);
});});