From jkiehl at riotgames.com Tue Apr 3 17:15:02 2018 From: jkiehl at riotgames.com (Josiah Kiehl) Date: Tue, 03 Apr 2018 21:15:02 +0000 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule Message-ID: I'm trying to execute this example code: https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython I realize the posted question is a few years old at this point... has something changed in how python, compiled to a DLL via clr.CompileModule, is loaded? I'm getting this error when I run the code in the example at the above link: Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode $functionCode) at IronPython.Compiler.OnDiskScriptCode.Run() (full stack: https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc) My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. Am I missing something obvious or is there a better example to use? My end goal is to be able to take a python module defined in a file (foo.py) with some functions defined, compile it into a dll via CompileModule, then load it directly from the dll via ImportModule to skip the performance hit of interpreting the Python at runtime. Thanks! Josiah -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkiehl at riotgames.com Tue Apr 3 17:15:56 2018 From: jkiehl at riotgames.com (Josiah Kiehl) Date: Tue, 03 Apr 2018 21:15:56 +0000 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: Oh, I'm on dotnet 2.0.3, if that's relevant information. On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl wrote: > I'm trying to execute this example code: > > https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython > > I realize the posted question is a few years old at this point... has > something changed in how python, compiled to a DLL via clr.CompileModule, > is loaded? > > I'm getting this error when I run the code in the example at the above > link: > Unhandled Exception: System.TypeLoadException: Could not load type > 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, > Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. > at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode > $functionCode) > at IronPython.Compiler.OnDiskScriptCode.Run() > > (full stack: > https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc) > > My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded > IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. > > Am I missing something obvious or is there a better example to use? > > My end goal is to be able to take a python module defined in a file > (foo.py) with some functions defined, compile it into a dll via > CompileModule, then load it directly from the dll via ImportModule to skip > the performance hit of interpreting the Python at runtime. > > Thanks! > Josiah > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephane.lozier at gmail.com Tue Apr 3 17:39:39 2018 From: stephane.lozier at gmail.com (=?UTF-8?Q?St=C3=A9phane_Lozier?=) Date: Tue, 03 Apr 2018 21:39:39 +0000 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: The .NET Core version of IronPython does not support assembly generation. I haven't tried it myself, but you could probably compile the assembly using the full framework version and then run it with .NET Core 2.0 (assuming you're not using unsupported APIs). St?phane On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, wrote: > Oh, I'm on dotnet 2.0.3, if that's relevant information. > > On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl wrote: > >> I'm trying to execute this example code: >> >> https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython >> >> I realize the posted question is a few years old at this point... has >> something changed in how python, compiled to a DLL via clr.CompileModule, >> is loaded? >> >> I'm getting this error when I run the code in the example at the above >> link: >> Unhandled Exception: System.TypeLoadException: Could not load type >> 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, >> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. >> at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode >> $functionCode) >> at IronPython.Compiler.OnDiskScriptCode.Run() >> >> (full stack: >> https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc) >> >> My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded >> IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. >> >> Am I missing something obvious or is there a better example to use? >> >> My end goal is to be able to take a python module defined in a file >> (foo.py) with some functions defined, compile it into a dll via >> CompileModule, then load it directly from the dll via ImportModule to skip >> the performance hit of interpreting the Python at runtime. >> >> Thanks! >> Josiah >> >> >> _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > https://mail.python.org/mailman/listinfo/ironpython-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkiehl at riotgames.com Tue Apr 3 17:53:21 2018 From: jkiehl at riotgames.com (Josiah Kiehl) Date: Tue, 03 Apr 2018 21:53:21 +0000 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: Sorry if I'm not understanding... when you say "full framework version", do you mean the stand alone executable, ipy.exe? I compiled the dll with ipy.exe running a simple script: > ipy compile.py # compile.py import clr clr.CompileModules("compiled.dll", "test.py") This works just fine. Then I tried to load "compiled.dll" via the embedded IronPython in a simple dotnet CLI app and it produces the above error: ScriptEngine engine = Python.CreateEngine(); engine.Runtime.LoadAssembly(Assembly.LoadFile(@"C:\some\path\compiled.dll")); var scope = engine.Runtime.ImportModule("test"); Is that what's not supported? Loading the dll in the embedded IronPython? Thanks for your help, I am super hopeful I can get this working. Josiah On Tue, Apr 3, 2018 at 2:39 PM St?phane Lozier wrote: > The .NET Core version of IronPython does not support assembly generation. > I haven't tried it myself, but you could probably compile the assembly > using the full framework version and then run it with .NET Core 2.0 > (assuming you're not using unsupported APIs). > > St?phane > > > On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, wrote: > >> Oh, I'm on dotnet 2.0.3, if that's relevant information. >> >> On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl wrote: >> >>> I'm trying to execute this example code: >>> >>> https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython >>> >>> I realize the posted question is a few years old at this point... has >>> something changed in how python, compiled to a DLL via clr.CompileModule, >>> is loaded? >>> >>> I'm getting this error when I run the code in the example at the above >>> link: >>> Unhandled Exception: System.TypeLoadException: Could not load type >>> 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, >>> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. >>> at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode >>> $functionCode) >>> at IronPython.Compiler.OnDiskScriptCode.Run() >>> >>> (full stack: >>> https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc) >>> >>> My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded >>> IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. >>> >>> Am I missing something obvious or is there a better example to use? >>> >>> My end goal is to be able to take a python module defined in a file >>> (foo.py) with some functions defined, compile it into a dll via >>> CompileModule, then load it directly from the dll via ImportModule to skip >>> the performance hit of interpreting the Python at runtime. >>> >>> Thanks! >>> Josiah >>> >>> >>> _______________________________________________ >> Ironpython-users mailing list >> Ironpython-users at python.org >> https://mail.python.org/mailman/listinfo/ironpython-users >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephane.lozier at gmail.com Wed Apr 4 09:16:13 2018 From: stephane.lozier at gmail.com (=?UTF-8?Q?St=C3=A9phane_Lozier?=) Date: Wed, 4 Apr 2018 09:16:13 -0400 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: I assumed you were using .NET Core when you said you were using dotnet 2.0.3. So you are compiling using ipy.exe (which is a .NET 4.5 app) and then using the assembly from a .NET Core 2.0 application? The .NET Core API doesn't expose System.Runtime.CompilerServices.Closure so that might be the reason things are failing... St?phane On Tue, Apr 3, 2018 at 5:53 PM, Josiah Kiehl wrote: > Sorry if I'm not understanding... when you say "full framework version", > do you mean the stand alone executable, ipy.exe? > > I compiled the dll with ipy.exe running a simple script: > > > ipy compile.py > > # compile.py > import clr > > clr.CompileModules("compiled.dll", "test.py") > > This works just fine. > > Then I tried to load "compiled.dll" via the embedded IronPython in a > simple dotnet CLI app and it produces the above error: > > ScriptEngine engine = Python.CreateEngine(); > engine.Runtime.LoadAssembly(Assembly.LoadFile(@"C:\some\ > path\compiled.dll")); > var scope = engine.Runtime.ImportModule("test"); > > Is that what's not supported? Loading the dll in the embedded IronPython? > > Thanks for your help, I am super hopeful I can get this working. > Josiah > > On Tue, Apr 3, 2018 at 2:39 PM St?phane Lozier > wrote: > >> The .NET Core version of IronPython does not support assembly generation. >> I haven't tried it myself, but you could probably compile the assembly >> using the full framework version and then run it with .NET Core 2.0 >> (assuming you're not using unsupported APIs). >> >> St?phane >> >> >> On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, wrote: >> >>> Oh, I'm on dotnet 2.0.3, if that's relevant information. >>> >>> On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl >>> wrote: >>> >>>> I'm trying to execute this example code: >>>> https://stackoverflow.com/questions/32639893/call-dll- >>>> function-from-c-sharp-ironpython >>>> >>>> I realize the posted question is a few years old at this point... has >>>> something changed in how python, compiled to a DLL via clr.CompileModule, >>>> is loaded? >>>> >>>> I'm getting this error when I run the code in the example at the above >>>> link: >>>> Unhandled Exception: System.TypeLoadException: Could not load type >>>> 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, >>>> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. >>>> at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode >>>> $functionCode) >>>> at IronPython.Compiler.OnDiskScriptCode.Run() >>>> >>>> (full stack: https://gist.github.com/capoferro/ >>>> 5a730088582b8cd36591be510d6ca2fc) >>>> >>>> My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded >>>> IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. >>>> >>>> Am I missing something obvious or is there a better example to use? >>>> >>>> My end goal is to be able to take a python module defined in a file >>>> (foo.py) with some functions defined, compile it into a dll via >>>> CompileModule, then load it directly from the dll via ImportModule to skip >>>> the performance hit of interpreting the Python at runtime. >>>> >>>> Thanks! >>>> Josiah >>>> >>>> >>>> _______________________________________________ >>> Ironpython-users mailing list >>> Ironpython-users at python.org >>> https://mail.python.org/mailman/listinfo/ironpython-users >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkiehl at riotgames.com Wed Apr 4 13:38:46 2018 From: jkiehl at riotgames.com (Josiah Kiehl) Date: Wed, 04 Apr 2018 17:38:46 +0000 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: Oh! I understand now, thanks for clarifying. Yes, that's the problem. You mentioned that there is a "full framework" version I could compile my dlls with? I poked around the releases and I wasn't sure what you were referencing, specifically. I installed via the 2.7.8 msi from here: https://github.com/IronLanguages/ironpython2/releases. Is there a release with dotnet core or can I build one? I did notice that I can't compile via running the compile script in the embedded IronPython in dotnet core, as CompileModule is not supported. Thanks so much for answering my questions, this is extremely helpful. Josiah On Wed, Apr 4, 2018, 6:16 AM St?phane Lozier wrote: > I assumed you were using .NET Core when you said you were using dotnet > 2.0.3. So you are compiling using ipy.exe (which is a .NET 4.5 app) and > then using the assembly from a .NET Core 2.0 application? The .NET Core API > doesn't expose System.Runtime.CompilerServices.Closure so that might be the > reason things are failing... > > St?phane > > On Tue, Apr 3, 2018 at 5:53 PM, Josiah Kiehl wrote: > >> Sorry if I'm not understanding... when you say "full framework version", >> do you mean the stand alone executable, ipy.exe? >> >> I compiled the dll with ipy.exe running a simple script: >> >> > ipy compile.py >> >> # compile.py >> import clr >> >> clr.CompileModules("compiled.dll", "test.py") >> >> This works just fine. >> >> Then I tried to load "compiled.dll" via the embedded IronPython in a >> simple dotnet CLI app and it produces the above error: >> >> ScriptEngine engine = Python.CreateEngine(); >> >> engine.Runtime.LoadAssembly(Assembly.LoadFile(@"C:\some\path\compiled.dll")); >> var scope = engine.Runtime.ImportModule("test"); >> >> Is that what's not supported? Loading the dll in the embedded IronPython? >> >> Thanks for your help, I am super hopeful I can get this working. >> Josiah >> >> On Tue, Apr 3, 2018 at 2:39 PM St?phane Lozier >> wrote: >> >>> The .NET Core version of IronPython does not support assembly >>> generation. I haven't tried it myself, but you could probably compile the >>> assembly using the full framework version and then run it with .NET Core >>> 2.0 (assuming you're not using unsupported APIs). >>> >>> St?phane >>> >>> >>> On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, wrote: >>> >>>> Oh, I'm on dotnet 2.0.3, if that's relevant information. >>>> >>>> On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl >>>> wrote: >>>> >>>>> I'm trying to execute this example code: >>>>> >>>>> https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython >>>>> >>>>> I realize the posted question is a few years old at this point... has >>>>> something changed in how python, compiled to a DLL via clr.CompileModule, >>>>> is loaded? >>>>> >>>>> I'm getting this error when I run the code in the example at the above >>>>> link: >>>>> Unhandled Exception: System.TypeLoadException: Could not load type >>>>> 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, >>>>> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. >>>>> at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode >>>>> $functionCode) >>>>> at IronPython.Compiler.OnDiskScriptCode.Run() >>>>> >>>>> (full stack: >>>>> https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc) >>>>> >>>>> My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded >>>>> IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. >>>>> >>>>> Am I missing something obvious or is there a better example to use? >>>>> >>>>> My end goal is to be able to take a python module defined in a file >>>>> (foo.py) with some functions defined, compile it into a dll via >>>>> CompileModule, then load it directly from the dll via ImportModule to skip >>>>> the performance hit of interpreting the Python at runtime. >>>>> >>>>> Thanks! >>>>> Josiah >>>>> >>>>> >>>>> _______________________________________________ >>>> Ironpython-users mailing list >>>> Ironpython-users at python.org >>>> https://mail.python.org/mailman/listinfo/ironpython-users >>>> >>> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephane.lozier at gmail.com Thu Apr 5 09:45:11 2018 From: stephane.lozier at gmail.com (=?UTF-8?Q?St=C3=A9phane_Lozier?=) Date: Thu, 5 Apr 2018 09:45:11 -0400 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: It sounds like you were already doing what I was suggesting trying. The "full framework" version is what you get when you install using the MSI. The zip file in releases link contains the .NET Core version of the interpreter but like I said it doesn't support CompileModule. I think you may be out of luck on this since there's currently no way to compile the code for .NET Core and the assembly generated using full .NET doesn't work... St?phane On Wed, Apr 4, 2018 at 1:38 PM, Josiah Kiehl wrote: > Oh! I understand now, thanks for clarifying. Yes, that's the problem. You > mentioned that there is a "full framework" version I could compile my dlls > with? I poked around the releases and I wasn't sure what you were > referencing, specifically. > > I installed via the 2.7.8 msi from here: https://github.com/ > IronLanguages/ironpython2/releases. Is there a release with dotnet core > or can I build one? > > I did notice that I can't compile via running the compile script in the > embedded IronPython in dotnet core, as CompileModule is not supported. > > Thanks so much for answering my questions, this is extremely helpful. > Josiah > > On Wed, Apr 4, 2018, 6:16 AM St?phane Lozier > wrote: > >> I assumed you were using .NET Core when you said you were using dotnet >> 2.0.3. So you are compiling using ipy.exe (which is a .NET 4.5 app) and >> then using the assembly from a .NET Core 2.0 application? The .NET Core API >> doesn't expose System.Runtime.CompilerServices.Closure so that might be >> the reason things are failing... >> >> St?phane >> >> On Tue, Apr 3, 2018 at 5:53 PM, Josiah Kiehl >> wrote: >> >>> Sorry if I'm not understanding... when you say "full framework version", >>> do you mean the stand alone executable, ipy.exe? >>> >>> I compiled the dll with ipy.exe running a simple script: >>> >>> > ipy compile.py >>> >>> # compile.py >>> import clr >>> >>> clr.CompileModules("compiled.dll", "test.py") >>> >>> This works just fine. >>> >>> Then I tried to load "compiled.dll" via the embedded IronPython in a >>> simple dotnet CLI app and it produces the above error: >>> >>> ScriptEngine engine = Python.CreateEngine(); >>> engine.Runtime.LoadAssembly(Assembly.LoadFile(@"C:\some\ >>> path\compiled.dll")); >>> var scope = engine.Runtime.ImportModule("test"); >>> >>> Is that what's not supported? Loading the dll in the embedded IronPython? >>> >>> Thanks for your help, I am super hopeful I can get this working. >>> Josiah >>> >>> On Tue, Apr 3, 2018 at 2:39 PM St?phane Lozier < >>> stephane.lozier at gmail.com> wrote: >>> >>>> The .NET Core version of IronPython does not support assembly >>>> generation. I haven't tried it myself, but you could probably compile the >>>> assembly using the full framework version and then run it with .NET Core >>>> 2.0 (assuming you're not using unsupported APIs). >>>> >>>> St?phane >>>> >>>> >>>> On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, >>>> wrote: >>>> >>>>> Oh, I'm on dotnet 2.0.3, if that's relevant information. >>>>> >>>>> On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl >>>>> wrote: >>>>> >>>>>> I'm trying to execute this example code: >>>>>> https://stackoverflow.com/questions/32639893/call-dll- >>>>>> function-from-c-sharp-ironpython >>>>>> >>>>>> I realize the posted question is a few years old at this point... has >>>>>> something changed in how python, compiled to a DLL via clr.CompileModule, >>>>>> is loaded? >>>>>> >>>>>> I'm getting this error when I run the code in the example at the >>>>>> above link: >>>>>> Unhandled Exception: System.TypeLoadException: Could not load type >>>>>> 'System.Runtime.CompilerServices.Closure' from assembly >>>>>> 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken= >>>>>> b77a5c561934e089'. >>>>>> at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode >>>>>> $functionCode) >>>>>> at IronPython.Compiler.OnDiskScriptCode.Run() >>>>>> >>>>>> (full stack: https://gist.github.com/capoferro/ >>>>>> 5a730088582b8cd36591be510d6ca2fc) >>>>>> >>>>>> My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded >>>>>> IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. >>>>>> >>>>>> Am I missing something obvious or is there a better example to use? >>>>>> >>>>>> My end goal is to be able to take a python module defined in a file >>>>>> (foo.py) with some functions defined, compile it into a dll via >>>>>> CompileModule, then load it directly from the dll via ImportModule to skip >>>>>> the performance hit of interpreting the Python at runtime. >>>>>> >>>>>> Thanks! >>>>>> Josiah >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>> Ironpython-users mailing list >>>>> Ironpython-users at python.org >>>>> https://mail.python.org/mailman/listinfo/ironpython-users >>>>> >>>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkiehl at riotgames.com Thu Apr 5 12:23:06 2018 From: jkiehl at riotgames.com (Josiah Kiehl) Date: Thu, 05 Apr 2018 16:23:06 +0000 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: Got it. Thanks for the answers. I'll hang on to this work for future when compile module works in .net core. Is that an eventual plan? On Thu, Apr 5, 2018, 6:45 AM St?phane Lozier wrote: > It sounds like you were already doing what I was suggesting trying. The > "full framework" version is what you get when you install using the MSI. > The zip file in releases link contains the .NET Core version of the > interpreter but like I said it doesn't support CompileModule. > > I think you may be out of luck on this since there's currently no way to > compile the code for .NET Core and the assembly generated using full .NET > doesn't work... > > St?phane > > On Wed, Apr 4, 2018 at 1:38 PM, Josiah Kiehl wrote: > >> Oh! I understand now, thanks for clarifying. Yes, that's the problem. You >> mentioned that there is a "full framework" version I could compile my dlls >> with? I poked around the releases and I wasn't sure what you were >> referencing, specifically. >> >> I installed via the 2.7.8 msi from here: >> https://github.com/IronLanguages/ironpython2/releases. Is there a >> release with dotnet core or can I build one? >> >> I did notice that I can't compile via running the compile script in the >> embedded IronPython in dotnet core, as CompileModule is not supported. >> >> Thanks so much for answering my questions, this is extremely helpful. >> Josiah >> >> On Wed, Apr 4, 2018, 6:16 AM St?phane Lozier >> wrote: >> >>> I assumed you were using .NET Core when you said you were using dotnet >>> 2.0.3. So you are compiling using ipy.exe (which is a .NET 4.5 app) and >>> then using the assembly from a .NET Core 2.0 application? The .NET Core API >>> doesn't expose System.Runtime.CompilerServices.Closure so that might be the >>> reason things are failing... >>> >>> St?phane >>> >>> On Tue, Apr 3, 2018 at 5:53 PM, Josiah Kiehl >>> wrote: >>> >>>> Sorry if I'm not understanding... when you say "full framework >>>> version", do you mean the stand alone executable, ipy.exe? >>>> >>>> I compiled the dll with ipy.exe running a simple script: >>>> >>>> > ipy compile.py >>>> >>>> # compile.py >>>> import clr >>>> >>>> clr.CompileModules("compiled.dll", "test.py") >>>> >>>> This works just fine. >>>> >>>> Then I tried to load "compiled.dll" via the embedded IronPython in a >>>> simple dotnet CLI app and it produces the above error: >>>> >>>> ScriptEngine engine = Python.CreateEngine(); >>>> >>>> engine.Runtime.LoadAssembly(Assembly.LoadFile(@"C:\some\path\compiled.dll")); >>>> var scope = engine.Runtime.ImportModule("test"); >>>> >>>> Is that what's not supported? Loading the dll in the embedded >>>> IronPython? >>>> >>>> Thanks for your help, I am super hopeful I can get this working. >>>> Josiah >>>> >>>> On Tue, Apr 3, 2018 at 2:39 PM St?phane Lozier < >>>> stephane.lozier at gmail.com> wrote: >>>> >>>>> The .NET Core version of IronPython does not support assembly >>>>> generation. I haven't tried it myself, but you could probably compile the >>>>> assembly using the full framework version and then run it with .NET Core >>>>> 2.0 (assuming you're not using unsupported APIs). >>>>> >>>>> St?phane >>>>> >>>>> >>>>> On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, >>>>> wrote: >>>>> >>>>>> Oh, I'm on dotnet 2.0.3, if that's relevant information. >>>>>> >>>>>> On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl >>>>>> wrote: >>>>>> >>>>>>> I'm trying to execute this example code: >>>>>>> >>>>>>> https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython >>>>>>> >>>>>>> I realize the posted question is a few years old at this point... >>>>>>> has something changed in how python, compiled to a DLL via >>>>>>> clr.CompileModule, is loaded? >>>>>>> >>>>>>> I'm getting this error when I run the code in the example at the >>>>>>> above link: >>>>>>> Unhandled Exception: System.TypeLoadException: Could not load type >>>>>>> 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, >>>>>>> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. >>>>>>> at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode >>>>>>> $functionCode) >>>>>>> at IronPython.Compiler.OnDiskScriptCode.Run() >>>>>>> >>>>>>> (full stack: >>>>>>> https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc) >>>>>>> >>>>>>> My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded >>>>>>> IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. >>>>>>> >>>>>>> Am I missing something obvious or is there a better example to use? >>>>>>> >>>>>>> My end goal is to be able to take a python module defined in a file >>>>>>> (foo.py) with some functions defined, compile it into a dll via >>>>>>> CompileModule, then load it directly from the dll via ImportModule to skip >>>>>>> the performance hit of interpreting the Python at runtime. >>>>>>> >>>>>>> Thanks! >>>>>>> Josiah >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>> Ironpython-users mailing list >>>>>> Ironpython-users at python.org >>>>>> https://mail.python.org/mailman/listinfo/ironpython-users >>>>>> >>>>> >>> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From slide.o.mix at gmail.com Thu Apr 5 12:24:41 2018 From: slide.o.mix at gmail.com (Slide) Date: Thu, 05 Apr 2018 16:24:41 +0000 Subject: [Ironpython-users] Loading python compiled with clr.CompileModule In-Reply-To: References: Message-ID: It would require some additional features be implemented in .NET core to support it. On Thu, Apr 5, 2018 at 9:23 AM Josiah Kiehl wrote: > Got it. Thanks for the answers. I'll hang on to this work for future when > compile module works in .net core. Is that an eventual plan? > > On Thu, Apr 5, 2018, 6:45 AM St?phane Lozier > wrote: > >> It sounds like you were already doing what I was suggesting trying. The >> "full framework" version is what you get when you install using the MSI. >> The zip file in releases link contains the .NET Core version of the >> interpreter but like I said it doesn't support CompileModule. >> >> I think you may be out of luck on this since there's currently no way to >> compile the code for .NET Core and the assembly generated using full .NET >> doesn't work... >> >> St?phane >> >> On Wed, Apr 4, 2018 at 1:38 PM, Josiah Kiehl >> wrote: >> >>> Oh! I understand now, thanks for clarifying. Yes, that's the problem. >>> You mentioned that there is a "full framework" version I could compile my >>> dlls with? I poked around the releases and I wasn't sure what you were >>> referencing, specifically. >>> >>> I installed via the 2.7.8 msi from here: >>> https://github.com/IronLanguages/ironpython2/releases. Is there a >>> release with dotnet core or can I build one? >>> >>> I did notice that I can't compile via running the compile script in the >>> embedded IronPython in dotnet core, as CompileModule is not supported. >>> >>> Thanks so much for answering my questions, this is extremely helpful. >>> Josiah >>> >>> On Wed, Apr 4, 2018, 6:16 AM St?phane Lozier >>> wrote: >>> >>>> I assumed you were using .NET Core when you said you were using dotnet >>>> 2.0.3. So you are compiling using ipy.exe (which is a .NET 4.5 app) and >>>> then using the assembly from a .NET Core 2.0 application? The .NET Core API >>>> doesn't expose System.Runtime.CompilerServices.Closure so that might be the >>>> reason things are failing... >>>> >>>> St?phane >>>> >>>> On Tue, Apr 3, 2018 at 5:53 PM, Josiah Kiehl >>>> wrote: >>>> >>>>> Sorry if I'm not understanding... when you say "full framework >>>>> version", do you mean the stand alone executable, ipy.exe? >>>>> >>>>> I compiled the dll with ipy.exe running a simple script: >>>>> >>>>> > ipy compile.py >>>>> >>>>> # compile.py >>>>> import clr >>>>> >>>>> clr.CompileModules("compiled.dll", "test.py") >>>>> >>>>> This works just fine. >>>>> >>>>> Then I tried to load "compiled.dll" via the embedded IronPython in a >>>>> simple dotnet CLI app and it produces the above error: >>>>> >>>>> ScriptEngine engine = Python.CreateEngine(); >>>>> >>>>> engine.Runtime.LoadAssembly(Assembly.LoadFile(@"C:\some\path\compiled.dll")); >>>>> var scope = engine.Runtime.ImportModule("test"); >>>>> >>>>> Is that what's not supported? Loading the dll in the embedded >>>>> IronPython? >>>>> >>>>> Thanks for your help, I am super hopeful I can get this working. >>>>> Josiah >>>>> >>>>> On Tue, Apr 3, 2018 at 2:39 PM St?phane Lozier < >>>>> stephane.lozier at gmail.com> wrote: >>>>> >>>>>> The .NET Core version of IronPython does not support assembly >>>>>> generation. I haven't tried it myself, but you could probably compile the >>>>>> assembly using the full framework version and then run it with .NET Core >>>>>> 2.0 (assuming you're not using unsupported APIs). >>>>>> >>>>>> St?phane >>>>>> >>>>>> >>>>>> On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, >>>>>> wrote: >>>>>> >>>>>>> Oh, I'm on dotnet 2.0.3, if that's relevant information. >>>>>>> >>>>>>> On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl >>>>>>> wrote: >>>>>>> >>>>>>>> I'm trying to execute this example code: >>>>>>>> >>>>>>>> https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython >>>>>>>> >>>>>>>> I realize the posted question is a few years old at this point... >>>>>>>> has something changed in how python, compiled to a DLL via >>>>>>>> clr.CompileModule, is loaded? >>>>>>>> >>>>>>>> I'm getting this error when I run the code in the example at the >>>>>>>> above link: >>>>>>>> Unhandled Exception: System.TypeLoadException: Could not load type >>>>>>>> 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core, >>>>>>>> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. >>>>>>>> at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode >>>>>>>> $functionCode) >>>>>>>> at IronPython.Compiler.OnDiskScriptCode.Run() >>>>>>>> >>>>>>>> (full stack: >>>>>>>> https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc) >>>>>>>> >>>>>>>> My ipy.exe, which did the compilation, is 2.7.8.0 and my embedded >>>>>>>> IronPython is 2.7.8.1, though I get the same error on 2.7.8.0. >>>>>>>> >>>>>>>> Am I missing something obvious or is there a better example to use? >>>>>>>> >>>>>>>> My end goal is to be able to take a python module defined in a file >>>>>>>> (foo.py) with some functions defined, compile it into a dll via >>>>>>>> CompileModule, then load it directly from the dll via ImportModule to skip >>>>>>>> the performance hit of interpreting the Python at runtime. >>>>>>>> >>>>>>>> Thanks! >>>>>>>> Josiah >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>> Ironpython-users mailing list >>>>>>> Ironpython-users at python.org >>>>>>> https://mail.python.org/mailman/listinfo/ironpython-users >>>>>>> >>>>>> >>>> >> _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > https://mail.python.org/mailman/listinfo/ironpython-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: