- Notifications
You must be signed in to change notification settings - Fork749
Closed
Description
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 loadcoreclr
: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
- Get a device with macOS 15.1 and ARM64 architecture
- download blender 4.2
- Create the files
script.py
andruntimeconfig.json
in the same directory with the contents pasted below - Run blender with the commandline argument
-P path/to/script.py
(note: the crash occurs withoutruntimeconfig.json
as well, but i still included it for good measure)
script.py
defrun():try:importpythonnetexceptModuleNotFoundError:importpippip.main(["install","pythonnet"])try:importpythonnetexceptModuleNotFoundError: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")returnimportpathlibruntime_config_path=pathlib.Path(__file__).parent/"runtimeconfig.json"pythonnet.load("coreclr",runtime_config=runtime_config_path)fromSystemimportConsoleConsole.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
Failedtoinitializepythonnet:System.TypeInitializationException:Thetypeinitializerfor'Delegates'threwanexception.--->Python.Runtime.BadPythonDllException:Runtime.PythonDLLwasnotsetordoesnotpointtoasupportedPythonruntimeDLL.Seehttps://github.com/pythonnet/pythonnet#embedding-python-in-net--->System.MissingMethodException:FailedtoloadsymbolPy_Main:dlsym(RTLD_DEFAULT,Py_Main):symbolnotfoundatPython.Runtime.Platform.PosixLoader.GetFunction(IntPtrdllHandle,Stringname)in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Native/LibraryLoader.cs:line85atPython.Runtime.Runtime.Delegates.GetFunctionByName(StringfunctionName,IntPtrlibraryHandle)in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line296---Endofinnerexceptionstacktrace---atPython.Runtime.Runtime.Delegates.GetFunctionByName(StringfunctionName,IntPtrlibraryHandle)in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line300atPython.Runtime.Runtime.Delegates..cctor()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line38---Endofinnerexceptionstacktrace---atPython.Runtime.Runtime.Delegates.get_PyGILState_Ensure()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line319atPython.Runtime.Runtime.PyGILState_Ensure()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.cs:line712atPython.Runtime.PythonEngine.AcquireLock()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/PythonEngine.cs:line479atPython.Runtime.Py.GILState..ctor()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line27atPython.Runtime.Py.GIL()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line13atPython.Runtime.Loader.Initialize(IntPtrdata,Int32size)in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Loader.cs:line26atPython.Runtime.Runtime.Delegates.get_PyGILState_Ensure()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.Delegates.cs:line319atPython.Runtime.Runtime.PyGILState_Ensure()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Runtime.cs:line712atPython.Runtime.PythonEngine.AcquireLock()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/PythonEngine.cs:line479atPython.Runtime.Py.GILState..ctor()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line27atPython.Runtime.Py.GIL()in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Py.cs:line13atPython.Runtime.Loader.Initialize(IntPtrdata,Int32size)in/home/benedikt/dev/pythonnet/dist/.tmpXppz4v/pythonnet-3.0.4/src/runtime/Loader.cs:line26Traceback (mostrecentcalllast):File"/Users/user/Documents/Test/pythonnet_issue.py",line22,in<module>run()File"/Users/user/Documents/Test/pythonnet_issue.py",line17,inrunpythonnet.load("coreclr",runtime_config=config)File"/Users/user/Library/Application Support/Blender/4.2/extensions/.local/lib/python3.11/site-packages/pythonnet/__init__.py",line146,inloadraiseRuntimeError("Failed to initialize Python.Runtime.dll")RuntimeError:FailedtoinitializePython.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.
Metadata
Metadata
Assignees
Labels
No labels