带有 WebAssembly 的浏览器中的 Python,无需重新编译

Bas*_*asj 7 python emscripten webassembly

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

有没有办法在浏览器中使用 Python(使用 WebAssembly),使其工作方式如下:

  • 您只需将foo.jsfoo.wasmindex.html或类似的即用型文件放在一个目录中

  • main.py在目录下放一个文件, WebAssembly Python解释index.html器会在我们在浏览器中打开时自动启动,直接在浏览器中显示Python stdout

  • 您可以通过简单地添加 .py 文件来导入标准 Python 模块 main.py

例子:

pythoninbrowser.js
pythoninbrowser.wasm
index.html
main.py    --> containing "import bs4"
bs4/
    __init__.py
    ...all the rest of the BeautifulSoup module...
Run Code Online (Sandbox Code Playgroud)

另请参阅此问题