Is .NET Core or .NET 5.0 supported by Pythonnet
Asked Answered
J

1

14

I've been using Pythonnet for quite some time but always against .NET Framework 4.* With the recent release of .NET 5.0 I wanted to migrate my projects but I could not make it work for non-Framework versions (e.g. .NET Core 2.0, .NET Core 3.0, .NET 5.0)

Here is a very simple test I ran with .NET Framework 4.5:

namespace TestNet
{
    public class Dummy
    {
        private string _name;

        public Dummy(string name)
        {
            _name = name;
        }

        public string Hello(string name)
        {
            return $"Hello {name}, my name is {_name}";
        }
    }
}

This produces TestNet.dll then I run the following Python code:

>>> import clr
>>> clr.AddReference("TestNet")
<System.Reflection.RuntimeAssembly object at 0x000001899ACFABB0>
>>> from TestNet import Dummy
>>> d = Dummy("Bob")
>>> d.Hello("John")
'Hello John, my name is Bob'

So everything works fine.

Now, the exact same C# code but targeting .NET Core or .NET 5.0 will give me:

>>> import clr
>>> clr.AddReference("TestNet")
<System.Reflection.RuntimeAssembly object at 0x00000122AF0DABB0>
>>> from TestNet import Dummy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'TestNet'

My understanding is they are using CoreClr and not CLR and from Pythonnet website (https://pythonnet.github.io/):

Python.NET (pythonnet) is a package that gives Python programmers nearly seamless integration with the .NET 4.0+ Common Language Runtime (CLR)

Does anyone know if CoreClr is supported?

Thanks!

Env: Python 3.8/Windows 10

Jugate answered 14/12, 2020 at 1:25 Comment(8)
github.com/pythonnet/pythonnet/issues/857, your scenario for .NET Core is currently still a work in progressMilissa
@Milissa thanks for the very quick reply. Do you have any idea of the timeline for a first beta version?Jugate
It's still ongoing github.com/pythonnet/pythonnet/pull/1322, not even the dev release a timelineMilissa
@Martheen, does this mean that pythonnet is not available on Linux? I.e. it only supports the .NET Framework which is the Windows version, correct?Salyer
@Salyer Well it does support Mono, which is available on LinuxMilissa
Looks like we are getting closer to. NET 5 support github.com/pythonnet/pythonnet/pull/1373Velvavelvet
I'm using python.net with .NET 5.0 for my current use at the moment, and it worked splendidly from my end, I'm using a nuget preview released version: nuget.org/packages/pythonnetTreasonable
What @MaidenlessRunt said, using pythonnet with .NET6.0 and it works like it used to with .NET CORE 3.0. Might want to check your paths/ if the library exists etc.Salmons
V
0

Support for .NET 5 has been added to Python.NET although it's not released yet.

See here for an example

Pythonnet dotnet core 'No module named'

Velvavelvet answered 8/9, 2021 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.