Skip to content

[Bug]: Delvewheel update causes compatibility issues with IsolateNativeModules #762

@ericksoares13

Description

@ericksoares13

Describe the bug

When using GraalPy on Windows with python.IsolateNativeModules = true, importing native modules like numpy throws an OSError: The specified module could not be found.

As discussed with @msimacek, the underlying ctypes isolation issue is already fixed in master. However, this issue is specifically to track the remaining problem: the delvewheel tool was recently updated and currently has incompatibilities with how GraalPy invokes it.

Operating system

Windows

CPU architecture

x86_64

GraalPy version

GraalPy 3.12.8 (Oracle GraalVM Native 25.0.2)

JDK version

GraalVM JDK 21.0.4+8.1

Context configuration

OS: Windows 11

Steps to reproduce

  1. Create a virtual environment with GraalPy:
    graalpy -m venv --copies venv
  2. Activate and install the NumPy wheel:
    .\venv\Scripts\activate
    pip install .\numpy-2.2.4-graalpy312-graalpy250_312_native-win_amd64.whl
  3. Execute the following Java code:
@Test
void test() {
    final Path venvPath = Paths.get("tmp").resolve("venv");
    final String execPath = venvPath.resolve("Scripts").resolve("python.exe").toAbsolutePath().toString();
    final Map<String, String> pyVenvOptions = new HashMap<>();
    pyVenvOptions.put("python.Executable", execPath);
    pyVenvOptions.put("python.ForceImportSite", "true");
    pyVenvOptions.put("python.IsolateNativeModules", "true");

    final Context.Builder contextBuilder = Context.newBuilder("python")
            .allowIO(IOAccess.ALL)
            .allowNativeAccess(true)
            .allowExperimentalOptions(true)
            .allowCreateProcess(true)
            .options(pyVenvOptions);

    try (final Context context = contextBuilder.build()) {
        context.eval("python", "import numpy");
    }
}

Expected behavior

The numpy module should be imported successfully in the embedded Java context without throwing an OSError, just as it does when running from the GraalPy CLI directly.

Stack trace

[Complete log](https://graalvm.slack.com/files/U07B0FPSQTY/F0AUB0EBW3G/logs.txt)

[python::capi] WARNING: didn't register a native finalizer due to: Creating threads is not allowed.
[python::CtypesModuleBuiltins$DlOpenNode] FINE: Loading native library python-native.dll 
=== POLYGLOT EXCEPTION STACK TRACE ===
OSError: OSError: The specified module could not be found.

    at <python> <module>(Unknown)
    at org.graalvm.polyglot.Context.eval(Context.java:449)

Additional context

If pyVenvOptions.put("python.IsolateNativeModules", "true"); is removed from the Java setup, no error is thrown and the import works perfectly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions