Check the operation of Python for .NET in each environment

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.

Python.NET @ github

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.

.NET Framework 4 (success)

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.

.NET environment preparation

You don't have to do anything in particular. It's natural because it's a standard environment.

Preparing the Python environment

I just added the environment of Anaconda3, and I didn't need Tweak.

Operation check

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. .. ..

.NET Standard Library Call (Success)

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.

Mono (success)

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

.NET Standard Library Call (Success)

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

Check the operation of Python for .NET in each environment
Check the behavior of destructor in Python
Check the processing time and the number of calls for each process in python (cProfile)
Match the distribution of each group in Python
Code for checking the operation of Python Matplotlib
Switch the module to be loaded for each execution environment in Python
Check for the existence of BigQuery tables in Java
Check the asymptotic nature of the probability distribution in Python
Check for memory leaks in Python
Get the number of occurrences for each element in the list
Output the specified table of Oracle database in Python to Excel for each file
Google search for the last line of the file in Python
Get the index of each element of the confusion matrix in Python
Wrap (part of) the AtCoder Library in Cython for use in Python
Check the increase / decrease of Bitcoin for each address from the blockchain
[Understanding in the figure] Management of Python virtual environment by Pipenv
How to check the memory size of a variable in Python
Automatically resize screenshots for the App Store for each screen in Python
How to check the memory size of a dictionary in Python
LINEbot development, I want to check the operation in the local environment
python note: map -do the same for each element of the list
Check the existence of the file with python
About the virtual environment of python version 3.7
Summary of various for statements in Python
Check if the URL exists in Python
The result of installing python in Anaconda
Check the path of the Python imported module
MongoDB for the first time in Python
The basics of running NoxPlayer in Python
Pandas of the beginner, by the beginner, for the beginner [Python]
In search of the fastest FizzBuzz in Python
Status of each Python processing system in 2020
Prepare Python development environment for each project in Windows environment (VSCode + virtualEnvWrapper + Pylint)
Check the in-memory bytes of a floating point number float in Python
Memo of pixel position operation for image data in Python (numpy, cv2)
I made a program to check the size of a file in Python
[Python] Reason for dtype "int32" in Numpy (Windows environment) (as of September 2020)
Get the key for the second layer migration of JSON data in python
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
Output the number of CPU cores in Python
Check the operation of OpenCV3 installed by Anaconda
The story of low learning costs for Python
[Python] Sort the list of pathlib.Path in natural sort
Prepare the execution environment of Python3 with Docker
Check if the characters are similar in Python
Set up a dummy SMTP server in Python and check the operation of sending from Action Mailer
Unattended operation of Google Spreadsheets (etc.) in Python
Get the caller of a function in Python
View the result of geometry processing in Python
Make a copy of the list in Python
Check the date of the flag duty with Python
Install the python package in an offline environment
Tips for hitting the ATND API in Python
Find the divisor of the value entered in python
Image processing? The story of starting Python for
Find the solution of the nth-order equation in python
The story of reading HSPICE data in Python
[Note] About the role of underscore "_" in Python
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
Output in the form of a python array