Skip to content

Support scripting animation in python through PyO3#24

Draft
AzurIce wants to merge 17 commits intomainfrom
pyo3
Draft

Support scripting animation in python through PyO3#24
AzurIce wants to merge 17 commits intomainfrom
pyo3

Conversation

@AzurIce
Copy link
Owner

@AzurIce AzurIce commented Feb 13, 2025

No description provided.

@shenjackyuanjie
Copy link

关于 pyo3 在实际使用的时候可能会遇到的环境问题 (比如运行在一个启动了venv的终端里,但是并不使用)
可以参考 这里的代码

Comment on lines +172 to +188
pyo3::append_to_inittab!(ranimpy_module);
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
let sys = PyModule::import(py, "sys")?;

let executable = sys.getattr("executable")?;
let path = sys.getattr("path")?;
let version = sys.getattr("version")?;
// if args.len() == 2 {
// let venv_dir = Path::new(&args[1]);
let site_packages_path = dunce::canonicalize("../../.venv/Lib/site-packages").unwrap();
path.call_method1("append", (site_packages_path.to_str().unwrap(),))
.unwrap();
// }
println!("pyo3 sys.executable: {}", executable);
println!("pyo3 sys.path: {}", path);
println!("pyo3 sys.version: {}", version);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的环境处理应该将 173 的 pyo3::prepare_freethreaded_python();
替换为手动使用 ffi 直接对 PyConfig 进行设置
现在这样的实现并不能实现所需的功能

Comment on lines +212 to +229
fn test_python_module_methods() -> PyResult<()> {
pyo3::append_to_inittab!(ranimpy_module);
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
let sys = PyModule::import(py, "sys")?;

let executable = sys.getattr("executable")?;
let path = sys.getattr("path")?;
let version = sys.getattr("version")?;
// if args.len() == 2 {
// let venv_dir = Path::new(&args[1]);
let site_packages_path = dunce::canonicalize("../../.venv/Lib/site-packages").unwrap();
path.call_method1("append", (site_packages_path.to_str().unwrap(),))
.unwrap();
// }
println!("pyo3 sys.executable: {}", executable);
println!("pyo3 sys.path: {}", path);
println!("pyo3 sys.version: {}", version);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里同上

@AzurIce
Copy link
Owner Author

AzurIce commented Mar 19, 2025

关于 pyo3 在实际使用的时候可能会遇到的环境问题 (比如运行在一个启动了venv的终端里,但是并不使用)
可以参考 这里的代码

收到!十分感谢大佬,当时确实受这个问题折磨了很久ww(/。\)
目前 pyo3 的部分会暂时搁置一阵,过段时间我会去试试的~

@AzurIce AzurIce linked an issue Aug 6, 2025 that may be closed by this pull request
@AzurIce AzurIce removed a link to an issue Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants