From solarjoe at posteo.org Tue May 1 04:48:46 2018 From: solarjoe at posteo.org (Joe) Date: Tue, 1 May 2018 10:48:46 +0200 Subject: [Python.NET] Using multiple versions of the same DLL In-Reply-To: References: <6c167d141a19432ba7c8a8f5ba9cb98d@posteo.de> Message-ID: <505e51d9-8193-01e4-0bbc-a957ebbe903f@posteo.org> Yes, this is my question. The solution I found was to use System.Reflection.Assembly.LoadFile(fullPath) Kind regards, Joe Am 30.04.2018 um 04:58 schrieb Denis Akhiyarov: > I presume this is your question with an open bounty on it? > > https://stackoverflow.com/questions/49942487/python-for-net-how-to-explicitly-create-instances-of-c-sharp-classes-using-dif > > On Tue, Apr 24, 2018 at 7:04 AM, Joe > wrote: > > Hello, > > I found a rather old thread (2003) that describes how multiple > versions of a > DLL can be used. > > It states > > Things get a lot more complicated if you need to load more than one > version of a particular assembly (or more likely, you have a > dependency > on some library the does so). In this case, the names you access via > the CLR modules will always come from the first version of the > assembly loaded (which will always win in the internals of the > runtime). > > > (https://mail.python.org/pipermail/pythondotnet/2003-October/000010.html > ) > > Is this still correct or are there more convenient methods to do this? > > Kind regards, > Joe > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > > https://mail.python.org/mailman/listinfo/pythondotnet > > > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > From SSchukat at dspace.de Wed May 2 05:57:15 2018 From: SSchukat at dspace.de (Stefan Schukat) Date: Wed, 2 May 2018 09:57:15 +0000 Subject: [Python.NET] Error in calling Python class method from C# In-Reply-To: References: <19A216758DA7374193F26E107EDA37EA01ABC841C3@Exchange2010.dspace.de> Message-ID: <19A216758DA7374193F26E107EDA37EA01ABC87D60@Exchange2010.dspace.de> Hello, as I mentioned in my earlier mail the ?self? was missing for the instance method. The rest looks fine. Stefan From: PythonDotNet [mailto:pythondotnet-bounces+sschukat=dspace.de at python.org] On Behalf Of techi eth Sent: Monday, April 30, 2018 10:48 AM To: A list for users and developers of Python for .NET Subject: Re: [Python.NET] Error in calling Python class method from C# I have got success on doing. I just need to get review to ensure right. Please find below code snapshot. Class.py def test(): print "Test called" return 1 class ClassTest: def __init__(self) def Initalize(self): print "Initalize called" return 1 @staticmethod def Execute(): print "Execute called" return 1 ------------------------------------------------------------------------------------- Programme.cs PythonEngine.Initialize(); using (Py.GIL()) { //Creating module object PyObject testClassModule = PythonEngine.ImportModule("Class"); //Calling module method PyObject result = testClassModule.InvokeMethod("test"); Console.WriteLine("Test method result = {0}", result.ToString()); Dynamic classTest = testClassModule.GetAttr("ClassTest"); Dynamic tmp = classTest(); tmp.Initalize(); tmp.Execute(); } PythonEngine.Shutdown(); return 0; } On Mon, Apr 30, 2018 at 11:35 AM, techi eth > wrote: Iron Python is having way to do the same.Please check below link. https://stackoverflow.com/questions/579272/instantiating-a-python-class-in-c-sharp On Mon, Apr 30, 2018 at 10:36 AM, techi eth > wrote: Thanks for link, I have been through most of pages but not able to found same query. I am also not sure is this possible with Pyhton For .NET. Could you please give me below query answer. Can i create python class instance in C# programme ???? On Mon, Apr 30, 2018 at 8:34 AM, Denis Akhiyarov > wrote: You may get more feedback on stackoverflow than on this mailing list for questions like this: https://stackoverflow.com/questions/tagged/python.net?sort=newest&pageSize=50 On Fri, Apr 27, 2018 at 3:54 AM, techi eth > wrote: Any input on raised query. I think i am missing something very simple but not able to catch. Thanks On Thu, Apr 26, 2018 at 5:47 PM, techi eth > wrote: Yes,It will work with this way but i need to create multiple instance of same class.If you see other function (@Execute() ) with static was working. Please give me hint of doing without static. Thanks On Thu, Apr 26, 2018 at 4:54 PM, Stefan Schukat > wrote: Hello, you missed either @staticmethod decorator or the self argument for the Initialize method. Stefan From: PythonDotNet [mailto:pythondotnet-bounces+sschukat=dspace.de at python.org] On Behalf Of techi eth Sent: Wednesday, April 25, 2018 2:38 PM To: A list for users and developers of Python for .NET > Subject: [Python.NET] Error in calling Python class method from C# Hi, I am facing issue while calling python class function in C# programme. Can anyone give me hint what is wrong in below programme.While running I am getting error in invoking Initialize() function of class. Python module : def test(): print "Test called" return 1 class ClassTest: def __init__(self) def Initialize (): print " Initialize called" return 1 @staticmethod def Execute(): print "Execute called" return 1 C# Console Programme code snapshot : PythonEngine.Initialize(); using (Py.GIL()) { PyObject testClassModule = PythonEngine.ImportModule("Class"); //Calling module method PyObject result = testClassModule.InvokeMethod("test"); Console.WriteLine("Test method result = {0}", result.ToString()); PyObject classTest = testClassModule.GetAttr("ClassTest"); classTest.InvokeMethod("Initialize "); -----------------------------> Error classTest.InvokeMethod("Execute"); } PythonEngine.Shutdown(); _________________________________________________ Python.NET mailing list - PythonDotNet at python.org https://mail.python.org/mailman/listinfo/pythondotnet _________________________________________________ Python.NET mailing list - PythonDotNet at python.org https://mail.python.org/mailman/listinfo/pythondotnet _________________________________________________ Python.NET mailing list - PythonDotNet at python.org https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From techieth at gmail.com Fri May 4 09:05:14 2018 From: techieth at gmail.com (techi eth) Date: Fri, 4 May 2018 18:35:14 +0530 Subject: [Python.NET] mono_os_mutex_destroy issue with Python.NET Message-ID: Hi, I am getting below error when running C# programme with mono on Linux. Please suggest hint for solution. *Mono version : 5.8.1.0* *Pyhton.NET : 2.3.0* mono_os_mutex_destroy: pthread_mutex_destroy failed with "Device or resource busy" (16) Aborted Note : I am able to run only C# programme without issue but issue comes once i run nPython.exe coming with Python.NET. -------------- next part -------------- An HTML attachment was scrubbed... URL: From techieth at gmail.com Mon May 7 00:14:05 2018 From: techieth at gmail.com (techi eth) Date: Mon, 7 May 2018 09:44:05 +0530 Subject: [Python.NET] mono_os_mutex_destroy issue with Python.NET In-Reply-To: References: Message-ID: I have tried console progmramme (nPython.exe) coming with python.Net source & same is also resulting with above error. Can anybody suggest with which version of mono on Linux ARM target Python.NET will works. Thanks On Fri, May 4, 2018 at 6:35 PM, techi eth wrote: > Hi, > > > > I am getting below error when running C# programme with mono on Linux. > Please suggest hint for solution. > > > > *Mono version : 5.8.1.0* > > *Pyhton.NET : 2.3.0* > > > > mono_os_mutex_destroy: pthread_mutex_destroy failed with "Device or > resource busy" (16) > > Aborted > > > Note : I am able to run only C# programme without issue but issue comes > once i run nPython.exe coming with Python.NET. > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Mon May 7 10:03:38 2018 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Mon, 07 May 2018 14:03:38 +0000 Subject: [Python.NET] mono_os_mutex_destroy issue with Python.NET In-Reply-To: References: Message-ID: By ARM target you mean RASPBERRY PI? Search issue tracker for pythonnet on GitHub for this. But this is definitely out of scope of pythonnet, unless someone steps up to add CI testing for this target. On Sun, May 6, 2018, 11:14 PM techi eth wrote: > I have tried console progmramme (nPython.exe) coming with python.Net > source & same is also resulting with above error. > Can anybody suggest with which version of mono on Linux ARM target > Python.NET will works. > > Thanks > > > On Fri, May 4, 2018 at 6:35 PM, techi eth wrote: > >> Hi, >> >> >> >> I am getting below error when running C# programme with mono on Linux. >> Please suggest hint for solution. >> >> >> >> *Mono version : 5.8.1.0* >> >> *Pyhton.NET : 2.3.0* >> >> >> >> mono_os_mutex_destroy: pthread_mutex_destroy failed with "Device or >> resource busy" (16) >> >> Aborted >> >> >> Note : I am able to run only C# programme without issue but issue comes >> once i run nPython.exe coming with Python.NET. >> >> >> > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From krausda at gmx.de Mon May 14 12:41:05 2018 From: krausda at gmx.de (Daniel Krause) Date: Mon, 14 May 2018 18:41:05 +0200 Subject: [Python.NET] How to provide a variable of special type as method parameter Message-ID: Hi, I posted this question at stackoverflow some days ago: https://stackoverflow.com/questions/50254745/how-to-provide-a-variable-of-special-type-as-method-parameter I want to use a DLL with the help of Python for .NET (pythonnet). The methods in this DLL require (pointer to?) variables as parameters. I could figure out how to call a method and to provide an integer variable as parameter. I could not figure out how to provide such a parameter variable if a special type is required (here: FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[]). Here is a code summary, and the results: import clrimport sys sys.path.append("C:\\Users\\[...]\\FTD2XX_NET_v1.1.0\\") # path to dll clr.AddReference("System") clr.AddReference("FTD2XX_NET")from FTD2XX_NET import FTDIfrom System import UInt32 ftdi = FTDI() if __name__ == '__main__': # This method requires an integer as parameter, the code is working # M:FTD2XX_NET.FTDI.GetLibraryVersion(System.UInt32@) # summary: Gets the current FTD2XX.DLL driver version number. # returns: FT_STATUS value from FT_GetLibraryVersion in FTD2XX.DLL # param: name: LibraryVersion. The current library version. version_ = 0 # empty variable to provide as parameter ft_status, version = ftdi.GetLibraryVersion(version_) print('status: {}\nversion: {}'.format(ft_status, version)) # prints # status: 0 # version: 197140 # This method requires an FT_DEVICE_INFO_NODE[] as parameter, the code is not working # M:FTD2XX_NET.FTDI.GetDeviceList(FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[]) # summary: Gets information on all of the FTDI devices available. # returns: FT_STATUS value from FT_GetDeviceInfoDetail in FTD2XX.DLL # param: name: devicelist. # An array of type FT_DEVICE_INFO_NODE to contain the device information # for all available devices. # no idea how to create the fitting parameter FT_DEVICE_INFO_NODE[] devicelist_ = ftdi.FT_DEVICE_INFO_NODE() # empty variable to provide as parameter print(devicelist_.Flags, devicelist_.Type, devicelist_.ID, devicelist_.LocId, devicelist_.SerialNumber, devicelist_.Description, devicelist_.ftHandle) # prints # 0 0 0 0 None None 0 status, devicelist = FTDI.GetDeviceList(devicelist_) print(devicelist) # throws a TypeError: No method matches given arguments Here I found some c#-code where FT_DEVICE_INFO_NODE[] and GetDeviceList are used in a method: private int countDevices(){ FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; ftStatus = myDevice.GetNumberOfDevices(ref ftdiDeviceCount); if (ftStatus != FTDI.FT_STATUS.FT_OK) return 0; if (ftdiDeviceCount > 0) { //allocate device info list ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; //populate list ftStatus = myDevice.GetDeviceList(ftdiDeviceList); if (ftStatus == FTDI.FT_STATUS.FT_OK) { return (int)ftdiDeviceCount; } else return 0; } else return 0;} So my main problem seems to be the transition of ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; to valid python for .NET - code. It would be great if someone could provide some hints. Thanks Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From vs.bhadauriya at live.com Tue May 22 08:32:45 2018 From: vs.bhadauriya at live.com (=?utf-8?B?TmljS3og8J+Rqw==?=) Date: Tue, 22 May 2018 12:32:45 +0000 Subject: [Python.NET] Need help in converting function of .net to python Message-ID: Hi All, I hope all of you are doing well in your life. I want to convert this .net function in python private static string decrypt(string enctxt) { string dectext = ""; string encryptKey = "HECT17IPWORI1702"; byte[] encArr = Convert.FromBase64String(enctxt); using (Aes aesObj = Aes.Create()) { Rfc2898DeriveBytes objRfc = new Rfc2898DeriveBytes(encryptKey, new Byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); aesObj.Key = objRfc.GetBytes(32); aesObj.IV = objRfc.GetBytes(16); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, aesObj.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(encArr, 0, encArr.Length); cs.Close(); } dectext = Encoding.Unicode.GetString(ms.ToArray()); } } return dectext; } Please guide me how to convert it into python. Regards Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From jared at quantconnect.com Tue May 22 08:39:37 2018 From: jared at quantconnect.com (Jared Broad) Date: Tue, 22 May 2018 08:39:37 -0400 Subject: [Python.NET] Speeding Up Pythonnet Message-ID: Hi All, my first post here =) We're using Pythonnet in LEAN - an open source algorithmic trading platform. We load the python object and then we make it look like a C# interface . Each time a method/property is called we see 75% of the time being spent in Pythonnet; and only 10-25% being actual work. The raw C# version of LEAN runs up to 20x faster than our python layer; we're looking for suggestions on how to improve the speed of the library / C#-Py interop. Thanks Jared -- Jared Broad www.quantconnect.com Phone-USA: +1 917 327 0556 *Democratizing Finance, Empowering Individuals* Facebook | Twitter | LinkedIn | Skype: jaredbroad We're recruiting! Join us and make your mark on the future of finance -------------- next part -------------- An HTML attachment was scrubbed... URL: From ihannah at meniscus.co.uk Wed May 30 10:52:59 2018 From: ihannah at meniscus.co.uk (Ian Hannah) Date: Wed, 30 May 2018 15:52:59 +0100 Subject: [Python.NET] Passing a C# DateTime object to a Python script Message-ID: <000c01d3f825$e7ae8910$b70b9b30$@meniscus.co.uk> Hi, I have a simple python script: def test(datetime_or_doy): print datetime_or_doy.strftime('%m/%d/%Y') and I am using Python for .NET to try and call this method as follows: dynamic np = Py.Import(@"pvlib"); double d = np.irradiance.test(DateTime.Now); and I get the error: Python.Runtime.PythonException: 'AttributeError : 'DateTime' object has no attribute 'strftime'' Clearly I need to pass a Python datetime object from the C# code but how do I do that? Thanks Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: