Python for .NET can be installed in various environments, but there is not much information on which combination is possible. I will focus on what I have done. I will describe in order from the one that was made.
Oh, I only use Python-> .NET direction calls, not Embedded Scripting.
Windows 10
I think that this is mainly used on Windows 10, so I will try it thicker.
The fixed conditions are as follows.
Since it is written as follows, I basically use 3.7.
Python 3.8.0 support Some features are disabled in Python 3.8.0 because of this bug in Python. The error is System.EntryPointNotFoundException : Unable to find an entry point named 'Py_CompileString' in DLL 'python38'. This will be fixed in Python 3.8.1.
I'd like .NET 5 to come out soon, but I have to wait for a while, so from the legacy side. I am using .NET 4.6 pre-installed on Windows 10.
You don't have to do anything in particular. It's natural because it's a standard environment.
I just added the environment of Anaconda3, and I didn't need Tweak.
If this doesn't give you an error, you should be fine.
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form
import sys
print("OS : ", Environment.OSVersion.VersionString)
print("Python : " ,sys.version)
print(".NET : ", Environment.Version.ToString())
print("pythonnet : " , clr.__version__)
Execution result
OS : Microsoft Windows NT 10.0.19041.0
python : 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
.NET : 4.0.30319.42000
pythonnet : 2.4.0
The version of Windows 10 is suspicious, but there. .. ..
From the latest version 8.x of BayesServer, it may be provided in .NET Standard, Python for .NET (.NET Framework)-> Validated calls to the .NET Standard library.
sys.path.append("C:/Program Files/Bayes Server/Bayes Server 8.16/API/DotNet/Standard20/")
clr.AddReference("BayesServer")
import BayesServer
network = Network()
network.Load("model.bayes")
print(network.Links.Count)
.NET Core
I don't know if desktop developers are at the level where it's time to consider migrating to .NET Core, but .NET Core 3.1 brings features that are as good as the Framework. But unfortunately pythonnet isn't ready yet and it seems that you can't run Python from .NET Core. (In the first place, such a thing is not allowed)
Support for .NET Core? #243 @ github
.NET Core (CoreCLR) does not provide reverse pinvoke like .NET Framework on Windows, neither C++/CLI. Hence the only way to get this working is to embed .NET Core using C-API, like this is done for Mono. The problem is that C-API for CoreCLR looks quite different from Mono.
CoreCLR does not support reverse P / Invoke, so I write it as impossible game. Isn't it okay to make .NET Core from Python? I think.
However! The above is the information for 2016, from which the situation is described in the following issue.
.NET Core support and CoreCLR embedding - cross-platform API #96 @ github
denfromufa commented on Oct 17, 2018 According to the following support status.
Platform | .NET-> Python | Python -> .NET |
---|---|---|
Windows | Tested | Coded (npython.exe) |
Linux | Tested | Tested (npython.exe) |
OSX | Coded | Coded (npython.exe) |
When calling .NET Core from Python, it seems that there are quite a few restrictions such as npython limitation.
Linux
It works as a bridge for Mono on Linux.
Install Mono below. The execution environment is almost ready.
sudo apt-get install mono-complete
Load pythonnet and check it in the same way.
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form
I am using the environment on Ubuntu 16.04.6 LTS.
import sys
print("OS : ", Environment.OSVersion.VersionString)
print("python : " ,sys.version)
print(".NET : ", Environment.Version.ToString())
print("pythonnet : " , clr.__version__)
Execution result
OS : Unix 4.15.0.1063
python : 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31)
[GCC 7.3.0]
.NET : 4.0.30319.42000
pythonnet : 2.4.0
Verified Python for .NET (Mono)-> .NET Standard .NET Standard library calls.
sys.path.append("/mnt/azmnt/code/Users/bayesserver-8.16/DotNet/Standard20")
clr.AddReference("BayesServer")
import BayesServer
network = Network()
network.Load("model.bayes")
print(network.Links.Count)
It seems to be working somehow.
.NET Core
Mac OSX
Mono
.NET Core
Recommended Posts