Python - C# interoperability

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mc

    #1

    Python - C# interoperability

    Is there an easy way to compile a Python class (or set of classes) into
    a .DLL that a C# program can call? Or otherwise to use an existing
    library of Python classes from a C# program as seamlessly as possible?

  • =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

    #2
    Re: Python - C# interoperabilit y

    mc schrieb:
    Is there an easy way to compile a Python class (or set of classes) into
    a .DLL that a C# program can call? Or otherwise to use an existing
    library of Python classes from a C# program as seamlessly as possible?
    You should take a look at IronPython, which supports that kind of thing.

    Regards,
    Martin

    Comment

    • Bruno Desthuilliers

      #3
      Re: Python - C# interoperabilit y

      mc a écrit :
      Is there an easy way to compile a Python class (or set of classes) into
      a .DLL that a C# program can call? Or otherwise to use an existing
      library of Python classes from a C# program as seamlessly as possible?
      >
      I can't tell if that'll do, but have you looked at IronPython ?

      Comment

      • =?iso-8859-1?q?Luis_M._Gonz=E1lez?=

        #4
        Re: Python - C# interoperabilit y


        mc wrote:
        Is there an easy way to compile a Python class (or set of classes) into
        a .DLL that a C# program can call? Or otherwise to use an existing
        library of Python classes from a C# program as seamlessly as possible?
        I'm affraid this is not possible.
        Ironpython (the .NET python implementation) can consume assemblies
        written in other statically typed languages, such as c#, but not the
        other way around.
        This is because Ironpython is still a dynamic language, and the lack of
        type information makes it impossible to be compiled as c#.

        For the time being, if you really need to write reusable assemblies
        that could be consumed from other .NET languages, you shouldn't use
        Ironpython.
        You should use c#, vb.net or any other static language implementation
        for .NET.

        If you want a more "pythonic" alternative, you could use Boo (
        http://boo.codehaus.org ).
        It's a static language with a python-like syntax, and it's very easy to
        pick up if you already know python.

        For consuming Boo assemblies from Ironpython, you should compile them
        as .DLL, and place them into a "DLLs" folder in your Ironpython root
        directory (where ipy.exe is located).
        Then you simply import them as you would with any other python module.
        Make sure to add also the boo assembly. If you are using c# instead,
        you don't have to add anything else.

        Hope this helps,
        Luis

        Comment

        • mc

          #5
          Re: Python - C# interoperabilit y

          Thanks to all who responded. It appears that there may be a solution
          as follows:

          use jythonc to turn Python program into Java bytecode

          use Microsoft's jbimp to turn Java bytecode into .NET DLL

          It sounds roundabout, but I am investigating.

          Comment

          • sturlamolden

            #6
            Re: Python - C# interoperabilit y


            mc wrote:
            Is there an easy way to compile a Python class (or set of classes) into
            a .DLL that a C# program can call? Or otherwise to use an existing
            library of Python classes from a C# program as seamlessly as possible?
            One way is to use IronPython if you don't need modules written for
            CPython.

            Another option is to use a COM wrapper, e.g. using win32com in Python.

            A third option is to embed a Python interpreter in your C# app.

            Comment

            • Larry Bates

              #7
              Re: Python - C# interoperabilit y

              mc wrote:
              Is there an easy way to compile a Python class (or set of classes) into
              a .DLL that a C# program can call? Or otherwise to use an existing
              library of Python classes from a C# program as seamlessly as possible?
              >
              You can write COM objects that can be called from C# (or basically ANY
              other language that can call COM objects) quite easily and compile them
              with py2exe for distribution without python itself.

              -Larry Bates

              Comment

              Working...