Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

DllNotFoundException with .NET8 on Ubuntu 24.04.2 #2582

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
sky9mike opened this issue Apr 12, 2025 · 0 comments
Closed

DllNotFoundException with .NET8 on Ubuntu 24.04.2 #2582

sky9mike opened this issue Apr 12, 2025 · 0 comments

Comments

@sky9mike
Copy link

sky9mike commented Apr 12, 2025

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.

@sky9mike sky9mike changed the title DllNotFoundException with .NET8 on Ubuntu DllNotFoundException with .NET8 on Ubuntu 24.04.2 Apr 12, 2025
@pythonnet pythonnet locked and limited conversation to collaborators Apr 14, 2025
@lostmsu lostmsu converted this issue into discussion #2583 Apr 14, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant