Date   

How to fetch an image from python to C# using Iron python 2.7

usmankaiz@...
 

Hi,
I am trying to use deep learning model for computer vision for gaming environment, the issue is, passing the image from c# to python is a bit slow, is there any a solution to make this process faster?

I just want the image and results processed by python to C# since other solutions have caused the lag/delay.

Regards,
Usman


Re: Speech Recognition inside Grasshopper for Rhino

Alex Earl
 

If the module requires a native built module, it will not work with IronPython. 


On Tue, Sep 3, 2019, 11:04 Povl Filip Sonne-Frederiksen via Groups.Io <psf=aarch.dk@groups.io> wrote:

Hey everyone,

I was hoping to maybe get some pointers. I’m trying to implement speech recognition using python inside rhino\grasshopper, which in turn relies on IronPython (2.7.8) as its platform.

So far I’ve managed to install SpeechRecognition 3.8.1 but this depends on PyAudio which is making all the trouble.

 

The error  I’m getting is: Python was built with Visual Studio version 6, and extensions need to be built with the same version of the compiler, but it isn't installed.

Do I need to get Visual Studio version 6 or is the some other compiler I can use, that will do the trick. (I’m on Windows 10 and have Visual Studio 2017)

 

Best

Povl

 

 

Full error message :

C:\IronPython 2.7>ipy -X:Frames -m pip install PyAudio-0.2.11.tar.gz

 

Processing c:\ironpython 2.7\pyaudio-0.2.11.tar.gz

Installing collected packages: PyAudio

  Running setup.py install for PyAudio ... error

    Complete output from command "C:\IronPython 2.7\ipy.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\xyz\\appdata\\local\\temp\\pip-earp3s-build\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\xyz\appdata\local\temp\pip-v4gaeb-record\install-record.txt --single-version-externally-managed --compile:

    running install

    running build

    running build_py

    creating build

    creating build\lib.cli-2.7

    copying src\pyaudio.py -> build\lib.cli-2.7

    warning: build_py: byte-compiling is disabled, skipping.

 

    running build_ext

    building '_portaudio' extension

    error: Python was built with Visual Studio version 6, and extensions need to be built with the same version of the compiler, but it isn't installed.

 

    ----------------------------------------

Command ""C:\IronPython 2.7\ipy.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\xyz\\appdata\\local\\temp\\pip-earp3s-build\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\xyz\appdata\local\temp\pip-v4gaeb-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\xyz\appdata\local\temp\pip-earp3s-build\

 

You are using pip version 8.1.1, however version 19.2.3 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.


Povl Filip Sonne-Frederiksen
Research Assistant
Cand.arch.
Logo
T: +45 8936 0000
E: psf@...
W: aarch.dk
Tagline


Speech Recognition inside Grasshopper for Rhino

psf@...
 

Hey everyone,

I was hoping to maybe get some pointers. I’m trying to implement speech recognition using python inside rhino\grasshopper, which in turn relies on IronPython (2.7.8) as its platform.

So far I’ve managed to install SpeechRecognition 3.8.1 but this depends on PyAudio which is making all the trouble.

 

The error  I’m getting is: Python was built with Visual Studio version 6, and extensions need to be built with the same version of the compiler, but it isn't installed.

Do I need to get Visual Studio version 6 or is the some other compiler I can use, that will do the trick. (I’m on Windows 10 and have Visual Studio 2017)

 

Best

Povl

 

 

Full error message :

C:\IronPython 2.7>ipy -X:Frames -m pip install PyAudio-0.2.11.tar.gz

 

Processing c:\ironpython 2.7\pyaudio-0.2.11.tar.gz

Installing collected packages: PyAudio

  Running setup.py install for PyAudio ... error

    Complete output from command "C:\IronPython 2.7\ipy.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\xyz\\appdata\\local\\temp\\pip-earp3s-build\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\xyz\appdata\local\temp\pip-v4gaeb-record\install-record.txt --single-version-externally-managed --compile:

    running install

    running build

    running build_py

    creating build

    creating build\lib.cli-2.7

    copying src\pyaudio.py -> build\lib.cli-2.7

    warning: build_py: byte-compiling is disabled, skipping.

 

    running build_ext

    building '_portaudio' extension

    error: Python was built with Visual Studio version 6, and extensions need to be built with the same version of the compiler, but it isn't installed.

 

    ----------------------------------------

Command ""C:\IronPython 2.7\ipy.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\xyz\\appdata\\local\\temp\\pip-earp3s-build\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\xyz\appdata\local\temp\pip-v4gaeb-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\xyz\appdata\local\temp\pip-earp3s-build\

 

You are using pip version 8.1.1, however version 19.2.3 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.


Povl Filip Sonne-Frederiksen
Research Assistant
Cand.arch.
Logo
T: +45 8936 0000
E: psf@...
W: aarch.dk
Tagline


Re: How to support debug in IronPython in .NET software

László Frank
 

Hello,

I am also developing a .Net based debugger and code reflector for IronPython so I would find interesting the "offical" answer. 
Till that time, as a starting point you may want to look at this article, my debugger code is mostly based on that.

Regards,
Laszlo

On Thu, Aug 8, 2019 at 8:15 PM Hailiang Shen <hailiang@...> wrote:

Hello all, our .NET program supports IronPython scripting. We are trying to support debugging (e.g. set break point, step into, step over, run to breakpoint). A script can get/set data in the .NET program. The script is run in the same thread as our script editor UI. I have a few questions as below:

 

  • Do we have to run the debug mode in a thread separate from the UI thread?
  • If so, what is the best way to modify our current get/set methods (many) so under script debug mode, program data can be get/set?
  • As you know, IronPython has excellent support for .NET libs. Will it be any issues to work with .NET libs under debug mode? Similarly, what about the impact on the IronPython libs (e.g. math, os)?
  • Will debug mode slow down a script run, comparing with the case of running without debug?

 

Are there other items we should pay attention to support debugging?

 

Thank you!

 

Hailiang


How to support debug in IronPython in .NET software

Hailiang Shen
 

Hello all, our .NET program supports IronPython scripting. We are trying to support debugging (e.g. set break point, step into, step over, run to breakpoint). A script can get/set data in the .NET program. The script is run in the same thread as our script editor UI. I have a few questions as below:

 

  • Do we have to run the debug mode in a thread separate from the UI thread?
  • If so, what is the best way to modify our current get/set methods (many) so under script debug mode, program data can be get/set?
  • As you know, IronPython has excellent support for .NET libs. Will it be any issues to work with .NET libs under debug mode? Similarly, what about the impact on the IronPython libs (e.g. math, os)?
  • Will debug mode slow down a script run, comparing with the case of running without debug?

 

Are there other items we should pay attention to support debugging?

 

Thank you!

 

Hailiang


Re: How to define a c# class to support IronPython power operator **

Hailiang Shen
 

Thanks for the speedy response. This sample works very well.

 

Hailiang

 

From: users@ironpython.groups.io <users@ironpython.groups.io> On Behalf Of Stéphane Lozier
Sent: July 5, 2019 5:23 PM
To: users@ironpython.groups.io
Subject: Re: [ironpython] How to define a c# class to support IronPython power operator **

 

There are a bunch of variations (e.g. using the name "__pow__", using the name "Power", static methods, instance methods), but here is one example:

 

        public class MyClass {
            private readonly double x;

            public MyClass(double x) {
                this.x = x;
            }

            public static MyClass __pow__(MyClass x, int y) {
                return new MyClass(Math.Pow(x.x, y));
            }

            public static MyClass __pow__(MyClass x, MyClass y) {
                return new MyClass(Math.Pow(x.x, y.x));
            }
        }

 

Stéphane

 

On Fri, Jul 5, 2019 at 4:43 PM Hailiang Shen <hailiang@...> wrote:

Hello all, I am defining a C# assembly to be used in IronPython. For one C# class, I need to support the IronPython power operator (**). For example in IronPython

 

MyClass1 ** 3 will automatically call my power function defined on my C# class.

MyClass1 ** MyClass2 will also automatically call my power function defined on my C# class.

 

It is simple to overload the overloadable operators https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/overloadable-operators, but I am not sure how to support the power operator. Could you suggest which C# operator I need to overload or is there one?

 

Hailiang


Re: How to define a c# class to support IronPython power operator **

Stéphane Lozier
 

There are a bunch of variations (e.g. using the name "__pow__", using the name "Power", static methods, instance methods), but here is one example:

        public class MyClass {
            private readonly double x;

            public MyClass(double x) {
                this.x = x;
            }

            public static MyClass __pow__(MyClass x, int y) {
                return new MyClass(Math.Pow(x.x, y));
            }

            public static MyClass __pow__(MyClass x, MyClass y) {
                return new MyClass(Math.Pow(x.x, y.x));
            }
        }

Stéphane


On Fri, Jul 5, 2019 at 4:43 PM Hailiang Shen <hailiang@...> wrote:

Hello all, I am defining a C# assembly to be used in IronPython. For one C# class, I need to support the IronPython power operator (**). For example in IronPython

 

MyClass1 ** 3 will automatically call my power function defined on my C# class.

MyClass1 ** MyClass2 will also automatically call my power function defined on my C# class.

 

It is simple to overload the overloadable operators https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/overloadable-operators, but I am not sure how to support the power operator. Could you suggest which C# operator I need to overload or is there one?

 

Hailiang


How to define a c# class to support IronPython power operator **

Hailiang Shen
 

Hello all, I am defining a C# assembly to be used in IronPython. For one C# class, I need to support the IronPython power operator (**). For example in IronPython

 

MyClass1 ** 3 will automatically call my power function defined on my C# class.

MyClass1 ** MyClass2 will also automatically call my power function defined on my C# class.

 

It is simple to overload the overloadable operators https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/overloadable-operators, but I am not sure how to support the power operator. Could you suggest which C# operator I need to overload or is there one?

 

Hailiang


Re: How do I access another api using Ironpython and VS2017

jpahto@...
 

System.Activator.GetObject requires to inputs: (Type, String)
If the String presents HKEY_CLASSES_ROOT, then how do I get the type from this.

I have tried the methods mentioned in guide:
https://ironpython.net/documentation/dotnet/dotnet.html#creating-a-com-object
But these do not seem to also work.


Re: How do I access another api using Ironpython and VS2017

Stéphane Lozier
 

Might just be a typo when you wrote your email, but clr.GetClrType(type("SldWorks.Application")) will give you System.String so obviously that won't work. If it's just a typo then I have no idea, you could try googling the error message ("Trying to create a proxy to an unbound type." in English).


Re: How do I access another api using Ironpython and VS2017

jpahto@...
 

If I try to call an open application:

swMain = System.Activator.GetObject(clr.GetClrType(type("SldWorks.Application")) ,"SldWorks.Application.24")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Yritetään luoda välityspalvelinta tyyppiin, jota ei ole sidottu
SystemError: Trying to create a proxt server to a type that has not been bind.


Re: How do I access another api using Ironpython and VS2017

jpahto@...
 

"SldWorks.Application" can be activated by the version number.

for SW 2012

("SldWorks.Application.20")

for SW 2013

("SldWorks.Application.21")

for SW 2014

("SldWorks.Application.22")

for SW 2015

("SldWorks.Application.23")

for SW 2016

("SldWorks.Application.24")

for SW 2017

("SldWorks.Application.25")

If I try to use this:
>>> System.Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application.24"))
<System.__ComObject object at 0x000000000000006C [System.__ComObject]>

And then:

>>> swApp = System.Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application.24"))
>>> dir(swApp)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
EnvironmentError: System.Runtime.InteropServices.COMException (0x8002802B): Elementtiä ei löydy. (HRESULT-poikkeus: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))
   kohteessa System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   kohteessa Microsoft.Scripting.ComInterop.ComRuntimeHelpers.GetITypeInfoFromIDispatch(IDispatch dispatch, Boolean throwIfMissingExpectedTypeInfo)
   kohteessa Microsoft.Scripting.ComInterop.IDispatchComObject.EnsureScanDefinedMethods()
   kohteessa Microsoft.Scripting.ComInterop.IDispatchComObject.GetMemberNames(Boolean dataOnly)
   kohteessa IronPython.Runtime.Operations.PythonOps.GetAttrNames(CodeContext context, Object o)
   kohteessa IronPython.Modules.Builtin.dir(CodeContext context, Object o)
   kohteessa Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   kohteessa System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   kohteessa Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   kohteessa IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   kohteessa IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   kohteessa IronPython.Hosting.PythonCommandLine.<>c__DisplayClass27_0.<RunOneInteraction>b__0()


Re: How do I access another api using Ironpython and VS2017

jpahto@...
 

If I use:

swApp = System.Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application"))

and then:

dir(swApp), it throws:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
EnvironmentError: System.Runtime.InteropServices.COMException (0x8002802B): Elementtiä ei löydy. (HRESULT-poikkeus: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))
   kohteessa System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   kohteessa Microsoft.Scripting.ComInterop.ComRuntimeHelpers.GetITypeInfoFromIDispatch(IDispatch dispatch, Boolean throwIfMissingExpectedTypeInfo)
   kohteessa Microsoft.Scripting.ComInterop.IDispatchComObject.EnsureScanDefinedMethods()
   kohteessa Microsoft.Scripting.ComInterop.IDispatchComObject.GetMemberNames(Boolean dataOnly)
   kohteessa IronPython.Runtime.Operations.PythonOps.GetAttrNames(CodeContext context, Object o)
   kohteessa IronPython.Modules.Builtin.dir(CodeContext context, Object o)
   kohteessa Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   kohteessa System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   kohteessa Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   kohteessa IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   kohteessa Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   kohteessa IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   kohteessa IronPython.Hosting.PythonCommandLine.<>c__DisplayClass27_0.<RunOneInteraction>b__0()


Re: How do I access another api using Ironpython and VS2017

Stéphane Lozier
 

This is normal Python behavior:
>>> import sys as bla
>>> assert "path" in dir(bla)
>>> from bla import path
ImportError: No module named bla


Re: How do I access another api using Ironpython and VS2017

jpahto@...
 

I tried to look at the steps through IronPython Interactive window:

import clr
clr.AddreferenceToFile("SolidWorks.Interop.sldworks.dll")
import Solidworks.Interop.sldworks as SldWorks

After this:

type(SldWorks)
<type 'namespace#'>

dir(SldWorks)
shows the listing correctly.

Then:

from SldWorks import SldWorks
ImportError: No module named SldWorks


Re: How do I access another api using Ironpython and VS2017

Stéphane Lozier
 

Looking at a SolidWorks.Interop.sldworks.dll that I found on NuGet, it seems like SldWorks and ModelDoc2 are interfaces and not instances so the first argument is expected to be an instance of the interface (e.g. swApp.SldWorks.ActivateDoc(instance)). There appears to be classes which implement these interfaces (SldWorksClass and ModelDoc2Class) so maybe you could try using those?

Here's a thread about a similar problem (with a different interop assemble): https://mail.python.org/pipermail/ironpython-users/2016-January/017599.html


Re: How do I access another api using Ironpython and VS2017

jpahto@...
 

I have defined the search path for Solidworks\api\redist on VS2017.

I have defined in code:
   clr.Addreference("Solidworks.Interop.sldworks")
   import Solidworks.Interop.sldworks as swApp
   swApp.SldWorks.ActivateDoc() # Activate the currently open document on Solidworks
   Title = swApp.ModelDoc2.GetTitle()  # Idea is to get the file name as string

On __init__:
   self.ent = self.FindName('ShowFileName') # Get textbox name
   self.ent.Text = Title  # Show file name as textbox text

It feels like I'm not creating an instance to access the class correctly. This feels \\\// logically correct way for me, but I do not yet understand correctly the idea behind .NET and IronPython.
If I comment all the lines and release them one by one, the WPF Application stops working after I release the ActivateDoc line.


Re: How do I access another api using Ironpython and VS2017

Alex Earl
 

How does it go sideways? Without information on what is going wrong, it will be very hard to help you.


How do I access another api using Ironpython and VS2017

jpahto@...
 

Hello,

I would like to talk about this topic, as there is so scarcely information about this.

As an engineer I would like to find creative solutions to all kinds of problems that I have come across. One of these is a application programming that can pass data between design softwares. The problem is that I've come to a dead-end and I have been wracking my brain with this problem.

As it stands, I can't create a connection to a design program through my own Ironpython WPF Application. I have the required API files.I know that I need to use addReference. But after this it goes sideways. How do I create an instance for my use. All I get is the description of what type the method is under a class.

These are commonly available on C# and VBA and VB.NET, but there are no solutions for Pythonic way.


Re: .NET Core: Can't reach imported static C#-classes in IronPython using .NET Core

thomas.jh.jansson@...
 

This solved my problem, thank you!

/Thomas