rust与python_RustPython

RustPython 是一个由 Rust 编写的 Python 3 解释器。RustPython 可以嵌入到 Rust 程序中,使用 Python 作为应用程序的脚本语言,也可以将其编译为 WebAssembly,在浏览器中运行 Python。

19d8da87e68d9248e86693f694dadbde.png

用法:

RustPython 需要 Rust 1.43.0 或以上版本,可以使用以下命令检查 Rust 的版本:

rustc --version

如果想更新至最新版可以使用以下命令:

rustup update stable

要在本地构建 RustPython,可执行以下操作:

$ 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

还可以使用以下命令安装和运行 RustPython:

$ cargo install rustpython

$ rustpython

Welcome to the magnificent Rust Python interpreter

>>>>>

或通过conda包管理器:

$ conda install rustpython -c conda-forge

$ rustpython

WASI:

可以使用以下命令将 RustPython 编译为独立的 WebAssembly WASI 模块,以便可以在任何地方运行它。

$ wapm install rustpython

$ wapm run rustpython

>>>>> 2 + 2

4

建立 WASI 文件

使用以下方法构建 WebAssembly WASI 文件:

cargo build --release --target wasm32-wasi --features="freeze-stdlib"

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值