Python在浏览器中使用WebAssembly,无需重新编译

2024-05-13 15:03:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经看过了Compiling Python to WebAssembly,它的各种答案,各种项目(EmPython,EmCPythoncpython-emscripten,Pyodide等),但大多数时候,它需要重新编译或使用Docker等

有没有一种方法可以在浏览器中使用Python(与WebAssembly一起),使其工作方式如下:

  • 您只需将foo.jsfoo.wasmindex.html或类似的随时可用的文件放在目录中

  • 您将一个main.py文件放入目录,当我们在浏览器中打开index.html时,WebAssembly Python Interepter会自动启动,Python标准输出将直接显示在浏览器中

  • 只需沿main.py

例如:

pythoninbrowser.js
pythoninbrowser.wasm
index.html
main.py    --> containing "import bs4"
bs4/
    __init__.py
    ...all the rest of the BeautifulSoup module...

另见this issue


Tags: 文件thepy目录indexfoomainhtml