Skip to content

"No module named '_struct'" when using ctypes with "freeze-stdlib" feature #6044

Description

@1ndahous3

Summary

Windows 11, Rust nightly, symlinks (for ../Lib) configured, RustPython d8f1d18

Cargo.toml

[package]
name = "frozen_ctypes"
version = "0.1.0"
edition = "2024"

[dependencies]
rustpython-vm = { path = "RustPython/vm", features = ["freeze-stdlib"] }
rustpython-pylib = { path = "RustPython/pylib", features = ["freeze-stdlib"] }

src/main.rs

use rustpython_vm::Interpreter;
use rustpython_vm::AsObject;

fn main() {
    let script = "from ctypes import *";

    let interpreter = Interpreter::with_init(Default::default(), |vm| {
        vm.add_frozen(rustpython_pylib::FROZEN_STDLIB);
    });

    let _ = interpreter.enter(|vm| {

        let scope = vm.new_scope_with_builtins();

        vm.run_code_string(scope, script, "<script>".to_owned())
            .map(drop)
            .map_err(|e| {
                let err_str = vm.call_method(e.as_object(), "__str__", ())
                    .ok()
                    .and_then(|s| s.downcast::<rustpython_vm::builtins::PyStr>().ok())
                    .map(|s| s.as_str().to_string())
                    .unwrap_or_else(|| "<unprintable>".into());
                format!("Python error: {}", err_str)
            })
    }).expect("Failed to run script");
    println!("Script executed successfully.");
}

Expected

Script executed successfully

Actual

C:/Users/Admin/.cargo/bin/cargo.exe run --color=always --package frozen_ctypes --bin frozen_ctypes --profile dev
    Blocking waiting for file lock on build directory                                                                                                                                                                                                               
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.82s
     Running `target\debug\frozen_ctypes.exe`

thread 'main' panicked at src\main.rs:25:8:
Failed to run script: "Python error: No module named '_struct'"
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library\std\src\panicking.rs:697
   1: core::panicking::panic_fmt
             at /rustc/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library\core\src\panicking.rs:75
   2: core::result::unwrap_failed
             at /rustc/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library\core\src\result.rs:1761
   3: enum2$<core::result::Result<tuple$<>,alloc::string::String> >::expect<tuple$<>,alloc::string::String>
             at C:\Users\Admin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:1119
   4: frozen_ctypes::main
             at .\src\main.rs:25
   5: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at C:\Users\Admin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:253
   6: core::hint::black_box
             at C:\Users\Admin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\hint.rs:482
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\frozen_ctypes.exe` (exit code: 101)

Process finished with exit code 101

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions