Skip to content

DllNotFoundException with .NET8 on Ubuntu 24.04.2 #2582

Closed
@sky9mike

Description

@sky9mike

I have used Python.NET from C# on Windows for years (huge thank you to all). I'm now trying get some stuff running on Linux and .NET8.

Using latest nuget for Python.NET (3.0.5) everything works great under Windows. But on Ubuntu 24.04.2 LTS I get:

   Unhandled exception. System.TypeInitializationException: The type initializer for 'Delegates' threw an exception.
 ---> System.DllNotFoundException: Could not load /usr/lib/x86_64-linux-gnu/libpython3.12.so.1.0 with flags RTLD_NOW | RTLD_GLOBAL: /usr/lib/x86_64-linux-gnu/libpython3.12.so.1.0: cannot open shared object file: No such file or directory
   at Python.Runtime.Platform.PosixLoader.Load(String dllToLoad)
   at Python.Runtime.Runtime.Delegates.GetUnmanagedDll(String libraryName)
   at Python.Runtime.Runtime.Delegates..cctor()
   --- End of inner exception stack trace ---
   at Python.Runtime.Runtime.Delegates.get_Py_IsInitialized()
   at Python.Runtime.Runtime.Py_IsInitialized()
   at Python.Runtime.Runtime.<>c.<Initialize>b__32_0()
   at Python.Runtime.Runtime.TryUsingDll[T](Func`1 op)
   at Python.Runtime.Runtime.Initialize(Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize()

Python looks OK?

$ ls -l /usr/lib/x86_64-linux-gnu/libpython3.12.so*
lrwxrwxrwx 1 root root      20 Feb  4 08:48 /usr/lib/x86_64-linux-gnu/libpython3.12.so.1 -> libpython3.12.so.1.0
-rw-r--r-- 1 root root 9055112 Feb  4 08:48 /usr/lib/x86_64-linux-gnu/libpython3.12.so.1.0

Code:

using Python.Runtime;

Console.WriteLine("Starting up ...");

Runtime.PythonDLL = "/usr/lib/x86_64-linux-gnu/libpython3.12.so.1.0";
//Runtime.PythonDLL = @"C:\Skyworks\Git\Tools3\Misc\MiniPythonDistis\PythonForCBPro312\python312.dll";

Console.WriteLine("Initializing Python.NET ...");
PythonEngine.Initialize();
Console.WriteLine("Done");

using (Py.GIL())
{
    dynamic hello = Py.Import("hello");
    hello.say_hello();
}

Full C# project:
PythonDotNetDotNET8Sample.zip

Any tips? Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions