Call IronPython from standard Python

How can I call the IronPython function from Python? Is there an easy way for the two to interact. I need the flexibility of both the full set of correct Python libraries not available in IronPython, and the latest version of the CLR, which is currently not available in Python.net.

What I have tried so far is to compile the IronPython DLL, but I cannot get it to load correctly in Python.

My attempt to make IronPython n callable from Python

foo.py

def foo():
    print 'hello world'

compile_ipy.py

import clr
clr.CompileModules("foo.dll", "foo.py")

My attempt to call Iron Python from Python

call_ipy_from_py1.py

import ctypes
dll = ctypes.WindDLL('foo.dll')
dll.foo() # AttributeError: function 'foo' not found

call_ipy_from_py2.py

import ctypes
dll = ctypes.cdll.LoadLibrary('foo.dll')
dll.foo() # AttributeError: function 'foo' not found
+4
source share
1 answer

.NET DLL - , C DLL ( ctypes). Python.NET :

import clr # Imports Python.Runtime.dll
import foo # Imports foo.dll
foo.foo()

, " CLR, Python.net ". : http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet, CPython 3, .NET 4.5.1 .

+3

Source: https://habr.com/ru/post/1570161/


All Articles