- Notifications
You must be signed in to change notification settings - Fork1.3k
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
[dependencies]rustpython-stdlib ="0.4.0"rustpython-vm ="0.4.0"
importtimeprint("Hello, World!",time.time())fromutils.helperimportgreet#this line causes error.print(greet("World"))
defgreet(name):returnf"Hello,{name}!"
use rustpython_vmas vm;fnmain() -> vm::PyResult<()>{let vm = vm::Interpreter::with_init(Default::default(), |vm|{ vm.add_native_modules(rustpython_stdlib::get_module_inits());}); vm.enter(|vm|{ vm.insert_sys_path(vm.new_pyobj("python_project"))?;let scope = vm.new_scope_with_builtins();let source_path ="python_project/main.py";let source = std::fs::read_to_string(source_path).expect("unable to read main.py");let code_obj = vm.compile(&source, vm::compiler::Mode::Exec, source_path.into()).map_err(|err| vm.new_syntax_error(&err,Some(&source)))?;ifletErr(err) = vm.run_code_obj(code_obj, scope){ vm.print_exception(err);}Ok(())})}
thank you sir, really need help, it seems |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 4 comments 5 replies
-
Would you share the result of |
BetaWas this translation helpful?Give feedback.
All reactions
-
I update the rust code and output. |
BetaWas this translation helpful?Give feedback.
All reactions
-
maybe missing |
BetaWas this translation helpful?Give feedback.
All reactions
-
yes, I tried, but not work. here is my code: https://github.com/qzd1989/rust-rustpython-test thank you, sir. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Ensure the project works with regular python before attempting to use rustpython |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I run the same code in a installed python env, it works, and it doesn't work in an embed python env(same error, can't find module). and this line: vm.insert_sys_path(vm.new_pyobj("python_project"))?; I think it should work but it doesn't work... |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have used embeded cpython instead of rustpython. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Okay, found problem.
I regard this as a user experience bug not to warn common pitfall easy. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
thank you sir, I think the code comments and examples in RustPython are too few, making it unfriendly for beginners :( i have used embeded cpython, hope rustpython will become better. |
BetaWas this translation helpful?Give feedback.