RustPython基于 Rust 的 Python 解釋器
RustPython 是一個(gè)由 Rust 編寫的 Python 3 解釋器。RustPython 可以嵌入到 Rust 程序中,使用 Python 作為應(yīng)用程序的腳本語(yǔ)言,也可以將其編譯為 WebAssembly,在瀏覽器中運(yùn)行 Python。
用法:
RustPython 需要 Rust 1.43.0 或以上版本,可以使用以下命令檢查 Rust 的版本:
rustc --version
如果想更新至最新版可以使用以下命令:
rustup update stable
要在本地構(gòu)建 RustPython,可執(zhí)行以下操作:
$ git clone https://github.com/RustPython/RustPython
$ cd RustPython
# if you're on windows:
$ powershell scripts\symlinks-to-hardlinks.ps1
# --release is needed (at least on windows) to prevent stack overflow
$ cargo run --release demo.py
Hello, RustPython!
或使用交互式 shell:
$ cargo run --release
Welcome to rustpython
>>>>> 2+2
4
還可以使用以下命令安裝和運(yùn)行 RustPython:
$ cargo install rustpython
$ rustpython
Welcome to the magnificent Rust Python interpreter
>>>>>
或通過(guò)conda包管理器:
$ conda install rustpython -c conda-forge
$ rustpython
WASI:
可以使用以下命令將 RustPython 編譯為獨(dú)立的 WebAssembly WASI 模塊,以便可以在任何地方運(yùn)行它。
$ wapm install rustpython
$ wapm run rustpython
>>>>> 2 + 2
4
構(gòu)建 WASI 文件
使用以下方法構(gòu)建 WebAssembly WASI 文件:
cargo build --release --target wasm32-wasi --features="freeze-stdlib"評(píng)論
圖片
表情
