henon / Python.Included

A Python.NET based framework enabling .NET libraries to call into Python packages without depending on a local Python installation.
MIT License
321 stars 52 forks source link

.NET 5 and Ubuntu compatibility #23

Closed Dave3991 closed 3 years ago

Dave3991 commented 3 years ago

Enviroment: Ubuntu 20.04

Error:

   at Python.Runtime.Runtime.Py_IsInitialized()
   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()
   at PythonExecutor.Program.Main(String[] args) in /home/david/Documents/personal/gitlab/inventory-management/InventoryManagement/app/PythonExecutor/Program.cs:line 13

Process finished with exit code 134.

Steps to reproduce: run this code:

using System;
using Python.Runtime;

namespace PythonExecutor
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Environment.SetEnvironmentVariable("LD_DEBUG","true");
            PythonEngine.Initialize();
            dynamic sys=PythonEngine.ImportModule("sys");
            Console.WriteLine("Python version: " + sys.version);
        }
    }
}

I think it's because it's not multiplatform ?

henon commented 3 years ago

check the last comment of #1 maybe that is the problem for you too?

Dave3991 commented 3 years ago

I would like to try it, but I don't know how to remove "PYTHON_WITH_PYMALLOC" during build of pythonnet :(

henon commented 3 years ago

ok, let me update the nuget quickly. hang on

henon commented 3 years ago

I removed pymalloc from linux and mac versions of pythonnet for py3.8. check out the pythonnet nuget v2.5.1.1

Dave3991 commented 3 years ago

@henon I installed library you metioned and I'm getting different error, btw thanks for effort :+1:

Hello World!
Unhandled exception. System.MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
   at Python.Runtime.CodeGenerator..ctor()
   at Python.Runtime.DelegateManager..ctor()
   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()
   at PythonExecutor.Program.Main(String[] args) in /home/david/Documents/personal/gitlab/inventory-management/InventoryManagement/app/PythonExecutor/Program.cs:line 26

Process finished with exit code 134.
henon commented 3 years ago

With that I can't help you further. Please make a reproduction of the error without involvement of Python.Included so the pythonnet guys are not suspecting me of having done something wrong on my end and create an issue on their repo.

Dave3991 commented 3 years ago

I don't know what happend, but I try several other pythonnet nugets then I install back pythonnet_netstandard_py38_linux version 2.5.1.1 and this code starts to work

namespace PythonExecutor
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using (Py.GIL())
            {
                dynamic sys=PythonEngine.ImportModule("sys");
                Console.WriteLine("Python version: " + sys.version);
            }
        }
    }
}

@henon big thank you for your patience and willingness :+1: you are good guy