Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to embed python runtime into my app#3805

Answeredbyyouknowone
oovm asked this question inQ&A
Discussion options

I need a custom python runtime without stdlib, I saw an example of this:

https://github.com/RustPython/RustPython/blob/main/examples/hello_embed.rs

but the dependencerustpython_vm seems yanked:https://crates.io/crates/rustpython-vm

How can I do the embed today?

I also don't needfreeze-stdlib, can I set it directly toutf-8 here?

// set up the encodings search function
self.import("encodings",None,0).map_err(|import_err|{
let err =self.new_runtime_error(
"Could not import encodings. Is your RUSTPYTHONPATH set? If you don't have\
access to a consistent external environment (e.g. if you're embedding\
rustpython in another application), try enabling the freeze-stdlib feature"
.to_owned(),
);
err.set_cause(Some(import_err));
err
})?;

You must be logged in to vote

Try to use latest main branch instead of published version.

Even without stdlib, you have to embed a few python files. Skipping stdlib is possible but builtin-modules are necessary.https://docs.python.org/3/library/sys.html#sys.builtin_module_names

Replies: 1 comment 3 replies

Comment options

Try to use latest main branch instead of published version.

Even without stdlib, you have to embed a few python files. Skipping stdlib is possible but builtin-modules are necessary.https://docs.python.org/3/library/sys.html#sys.builtin_module_names

You must be logged in to vote
3 replies
@Rafael-Conde
Comment options

Hello there! Would you mind to help me too?

I created a new Rust binary project with cargo new and copy pasted thehello_embed.rs into the mymain.rs file. In theCargo.toml file I added

# ...Boilerplate cargo.toml stuff and then[dependencies]rustpython ={git ="http://github.com/rustpython/rustpython.git", features =["freeze-stdlib"]}

I believe I'm using the lastest version of this repo, but yet I still get an error where it can't findexternal crate rustpython_vm. I saw thatrustpython_vm is added as a dependency to Rustpython and not a member of the workspace, so because of that I don't know how to separate them.

Is the problem in the way I added rustpython?

Any pointers or help is appreciated! Happy Holidays!

PS: I typed the url from what I remembered but in reality I copy pasted from the GitHub copy button

@DimitrisJim
Comment options

Just renaming it should do it I believe:

rustpython-vm = {git = "http://github.com/rustpython/rustpython.git", features = ["freeze-stdlib"]}
@Rafael-Conde
Comment options

Appreciated!! it worked!! thank you!

Answer selected byoovm
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
4 participants
@oovm@youknowone@DimitrisJim@Rafael-Conde

[8]ページ先頭

©2009-2025 Movatter.jp