Visitar URL original
"No module named '_struct'" when using ctypes with "freeze-stdlib" feature · Issue #6044 · RustPython/RustPython · GitHub
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

  1. arihant2math commented on Jul 29, 2025

    @arihant2math
    Contributor

    Ctypes is not completely implemented.

  2. 1ndahous3 commented on Jul 29, 2025

    @1ndahous3
    ContributorAuthor

    @arihant2math is it right to expect correct work (as described) after solving all subtasks from #5572 or is this an independent/separate task.

  3. arihant2math commented on Jul 29, 2025

    @arihant2math
    Contributor

    Likely it would work as intended, yes. If everything in that issue is implemented then ctypes should work as expected minus bugs.

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