10000 Loading runtime in blender on macOS 15.1 causes `MissingMethodException` · Issue #2503 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Loading runtime in blender on macOS 15.1 causes MissingMethodException #2503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Justin113D opened this issue Nov 7, 2024 · 3 comments
Closed

Comments

@Justin113D
Copy link
Justin113D commented Nov 7, 2024

Environment

  • Pythonnet version: 3.0.4
  • Python version: 3.11.7
  • Operating System: macOS 15.1 (24B83), ARM64
  • .NET Runtime: 8.0

Details

I am using pythonnet for a blender extension, and for the most part, it works great!

However, recently a user reported that it does not run on their macOS system, which throws following error upon trying to load coreclr:
System.MissingMethodException: Failed to load symbol Py_Main: dlsym(RTLD_DEFAULT, Py_Main): symbol not found

The error does not occur when attempting to do so using the python executable shipped with blender directly.
It only happens when running from within blender itself.


Minimal Reproduction

  1. Get a device with macOS 15.1 and ARM64 architecture
  2. download blender 4.2
  3. Create the files script.py and runtimeconfig.json in the same directory with the contents pasted below
  4. Run blender with the commandline argument -P path/to/script.py

(note: the crash occurs without runtimeconfig.json as well, but i still included it for good measure)

script.py

def run():
    try:
        import pythonnet
    except ModuleNotFoundError:
        import pip
        pip.main(["install", "pythonnet"])

        try:
            import pythonnet
        except ModuleNotFoundError:
            print("Could not install python.net, please try running blender with admin rights or run a portable instance of blender in a directory with write access")
            return

    import pathlib
    runtime_config_path = pathlib.Path(__file__).parent / "runtimeconfig.json"
    pythonnet.load("coreclr", runtime_config=runtime_config_path)

    from System import Console
    Console.WriteLine("Pythonnet successfully loaded!")

run()

runtimeconfig.json

{
  "runtimeOptions": {
    "tfm": "net8.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "8.0.0"
    },
    "configProperties": {
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

Console output / Stacktrace

Failed to initialize pythonnet: System.TypeInitializationException: The type initializer for 'Delegates' threw an exception.
 ---> Python.Runtime.BadPythonDllException: Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net
 ---> System.MissingMethodException: Failed to load symbol Py_Main: dlsym(RTLD_DEFAULT, Py_Main): symbol not found
   at Python.Runtime.Platform.PosixLoader.GetFunction(IntPtr dllHandle, String name) in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Native/LibraryLoader.cs:line 85
   at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle) in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line 296
   --- End of inner exception stack trace ---
   at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle) in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line 300
   at Python.Runtime.Runtime.Delegates..cctor() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line 38
   --- End of inner exception stack trace ---
   at Python.Runtime.Runtime.Delegates.get_PyGILState_Ensure() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line 319
   at Python.Runtime.Runtime.PyGILState_Ensure() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.cs:line 712
   at Python.Runtime.PythonEngine.AcquireLock() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/PythonEngine.cs:line 479
   at Python.Runtime.Py.GILState..ctor() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line 27
   at Python.Runtime.Py.GIL() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line 13
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size) in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Loader.cs:line 26
   at Python.Runtime.Runtime.Delegates.get_PyGILState_Ensure() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line 319
   at Python.Runtime.Runtime.PyGILState_Ensure() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.cs:line 712
   at Python.Runtime.PythonEngine.AcquireLock() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/PythonEngine.cs:line 479
   at Python.Runtime.Py.GILState..ctor() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line 27
   at Python.Runtime.Py.GIL() in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line 13
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size) in /home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Loader.cs:line 26Traceback (most recent call last):
  File "/Users/user/Documents/Test/pythonnet_issue.py", line 22, in <module>
    run()
  File "/Users/user/Documents/Test/pythonnet_issue.py", line 17, in run
    pythonnet.load("coreclr", runtime_config=config)
  File "/Users/user/Library/Application Support/Blender/4.2/extensions/.local/lib/python3.11/site-packages/pythonnet/__init__.py", line 146, in load
    raise RuntimeError("Failed to initialize Python.Runtime.dll")
RuntimeError: Failed to initialize Python.Runtime.dll

Note:
Here, pythonnet is located in blenders extension folder, which ships pythonnet 3.0.4 via wheels.
Removing it does unfortunately not change the result.

@filmor
Copy link
Member
filmor commented Nov 8, 2024

Interesting. Apparently, in the way that Blender embeds Python, it skips the Py_Main symbol. Could you try out #2504?

@Justin113D
Copy link
Author

Yep, that fixed it!

@filmor
Copy link
Member
filmor commented Nov 8, 2024

Nice. Fix is merged in #2504. I would like to finish #2470 before releasing a new version, though.

@filmor filmor closed this as completed Nov 8, 2024
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

No branches or pull requests

2 participants
0