- Notifications
You must be signed in to change notification settings - Fork749
Closed
Description
Environment
- Pythonnet version:3.0.0.0
- Python version:3.8.5
- Operating System: Ubuntu 18.04 (Windows 10, WSL 2.0)
- .NET Runtime: Dotnet Core 5.0.201
Details
I am trying to execute a Python file in a dotnet core program. I get the newest source code from github, and compiled it successfully as a DLL accoding the guidence. The version of the DLL is 3.0.0.0. I add this DLL as a reference of the project, and compile the project successfully. And then I use the command 'dotnet run' to execute the code. An exception occours with message:Unhandled exception. System.TypeInitializationException: The type initializer for 'Python.Runtime.UcsMarshaler' threw an exception.
Code
program.cs
The exception occurs when trying to execute the line: PythonEngine.PythonHome = "/home/leo/Anaconda3";
usingPython.Runtime;usingSystem;usingSystem.IO;namespacePythonDotNet{classProgram{staticvoidMain(string[]args){try{PythonEngine.PythonHome="/home/leo/Anaconda3";PythonEngine.Initialize();varscript=File.ReadAllText("t1.py");PyDictlocals=newPyDict();PythonEngine.Exec(script,null,locals.Handle);}finally{PythonEngine.Shutdown();Console.WriteLine("Done...");Console.ReadKey();}}}}
python_dotnet.csproj
<ProjectSdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net5.0</TargetFramework> </PropertyGroup><ItemGroup> <ReferenceInclude="Python.Runtime"> <HintPath>ref/Python.Runtime.dll</HintPath> </Reference></ItemGroup> <ItemGroup> <NoneUpdate="t1.py"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup></Project>
command to run
dotnet run
Exception
The error message indicates that there is a file named 'lidbl.so'.
Unhandled exception. System.TypeInitializationException: The type initializer for 'Python.Runtime.UcsMarshaler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Delegates' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Python.Runtime.Runtime' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'libdl.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl.so: cannot open shared object file: No such file or directory at Python.Runtime.Platform.LinuxLoader.dlerror() at Python.Runtime.Platform.LinuxLoader.ClearError() in /home/leo/project/pythonnet/src/runtime/platform/LibraryLoader.cs:line 90 at Python.Runtime.Platform.LinuxLoader.GetFunction(IntPtr dllHandle, String name) in /home/leo/project/pythonnet/src/runtime/platform/LibraryLoader.cs:line 78 at Python.Runtime.Runtime.GetDefaultDllName() in /home/leo/project/pythonnet/src/runtime/runtime.cs:line 42 at Python.Runtime.Runtime..cctor() in /home/leo/project/pythonnet/src/runtime/runtime.cs:line 34 --- End of inner exception stack trace --- at Python.Runtime.Runtime.Delegates..cctor() in /home/leo/project/pythonnet/src/runtime/runtime.cs:line 2251 --- End of inner exception stack trace --- at Python.Runtime.Runtime.Delegates.get_PyUnicode_GetMax() in /home/leo/project/pythonnet/src/runtime/runtime.cs:line 2688 at Python.Runtime.Runtime.PyUnicode_GetMax() in /home/leo/project/pythonnet/src/runtime/runtime.cs:line 1559 at Python.Runtime.UcsMarshaler..cctor() in /home/leo/project/pythonnet/src/runtime/CustomMarshaler.cs:line 44 --- End of inner exception stack trace --- at Python.Runtime.UcsMarshaler.Py3UnicodePy2StringtoPtr(String s) in /home/leo/project/pythonnet/src/runtime/CustomMarshaler.cs:line 124 at Python.Runtime.PythonEngine.set_PythonHome(String value) in /home/leo/project/pythonnet/src/runtime/pythonengine.cs:line 97 at PythonDotNet.Program.Main(String[] args) in /home/leo/project/python_dotnet/Program.cs:line 14
Metadata
Metadata
Assignees
Labels
No labels