python.net

Call dll function works in IronPython, doesn't work in CPython3.4 gives “No method matches given arguments” error

烂漫一生 提交于 2019-12-04 16:34:06
For a project I need to include a DLL in Python. I'm using CPython3.4 and for including the dll I use pythonnet clr module (pythonnet-2.0.0.dev1-cp34-none-win_amd64.whl). In the dll I need a function that gives me a continuous update of a measurement. The dll is written in VB.net, the function that I need is shown below: Public Sub AdviseStart(ByVal item As Integer, ByVal a As Action(Of Object)) Implements IConversation.AdviseStart _parameterPoller.RegisterCallback(item, a) End Sub This is the code that I have written in python to call this function: import clr clr.AddReference('dll name')

Python .net framework reference argument Double[]&

≡放荡痞女 提交于 2019-12-04 10:55:31
Using the Python for .Net framework I'm trying to call a method from a C# .dll file. This method has the following arguments: public static void ExternalFunction( String Arg1, ref Double[]& Arg2, ); I understood the .Net framework converts Python floats to doubles. Now I would like to know how to make an array (double) and pass this as a reference to the external method. I've the following code: import clr clr.AddReference("MyDll") from MyLib import MyClass myName = "Benjamin" r = MyClass.ExternalFunction(myName, 0.0); print "Result: %s"%r You can call this method by providing a list (or tuple

Python and .NET integration

旧街凉风 提交于 2019-12-03 12:43:28
I'm currently looking at python because I really like the text parsing capabilities and the nltk library, but traditionally I am a .Net/C# programmer. I don't think IronPython is an integration point for me because I am using NLTK and presumably would need a port of that library to the CLR. I've looked a little at Python for .NET and was wondering if this was a good place to start. Is there a way to marshal a python class into C#? Also, is this solution still being used? Better yet, has anyone done this? One thing I am considering is just using a persistence medium as a go-between (parse in

IronPython invocation from C# (with SciPy) fails with ImportException: “No module named mtrand”

99封情书 提交于 2019-12-03 11:40:09
问题 I have a python library I am trying to use via IronPython (v2.7 RC1 [2.7.0.30]) invocation from C# application. The library uses NumPy and SciPy quite extensively, which does work with SciPy and NumPy for .NET when ran using ipy from command line like this: ipy.exe -X:Frames file_from_lib_importing_numpy.py However, when I invoke IronPython from C# using the code below, an exception is thrown: ImportException "No module named mtrand" at Microsoft.Scripting.Runtime.LightExceptions

Using C# Assemblies from Python via pythonnet

依然范特西╮ 提交于 2019-12-03 06:52:42
I am using Windows 7, 64-bit. I have managed to download and install pythonnet, so import clr clr.AddReference("System.Windows.Forms") from System.Windows.Forms import Form works fine. I have also downloaded and compiled/run a C# application which creates lots of assemblies. The application in question is ARDrone-Control-.NET. How can I use the generated DLL files from Python (and not just the built-in C# classes). Since I have never used C# (which is why I want to use the library from Python), I'd be happy to clarify the question. Just to provide another method: import sys sys.path.append("C:

Python for .NET: Using same .NET assembly in multiple versions

一笑奈何 提交于 2019-12-01 08:37:09
My problem: I have an assembly in 2 versions and want to use them at the same time in my Python project. The .NET libs are installed in GAC (MSIL), having the same public token: lib.dll (1.0.0.0) lib.dll (2.0.0.0) In Python I want something like that: import clr clr.AddReference("lib, Version=1.0.0.0, ...") from lib import Class myClass1 = Class() myClass1.Operation() *magic* clr.AddReference("lib, Version=2.0.0.0, ...") from lib import class myClass2 = Class() myClass2.Operation() myClass2.OperationFromVersion2() *other stuff* # both objects should be accessibly myClass1.Operation() myClass2

Efficiently convert System.Single[,] to numpy array

冷暖自知 提交于 2019-11-30 15:50:21
问题 Using Python 3.6 and Python for dotNET/pythonnet I have manged to get hold of an image array. This is of type System.Single[,] I'd like to convert that to a numpy array so that I can actually do something with it in Python. I've set up a function to step through that array and convert it elementwise - but is there something more sensible (and faster) that I could use? def MeasurementArrayToNumpy(TwoDArray): hBound = TwoDArray.GetUpperBound(0) vBound = TwoDArray.GetUpperBound(1) resultArray =

How to use a .NET method which modifies in place in Python?

孤者浪人 提交于 2019-11-30 15:14:51
I am trying to use a .NET dll in Python. In a .NET language the method requires passing it 2 arrays by reference which it then modifies: public void GetItems( out int[] itemIDs, out string[] itemNames ) How can I use this method in Python using the Python for .NET module? Edit: Forgot to mention this is in CPython not IronPython. Additional info. When I do the following: itemIDs = [] itemNames = [] GetItems(itemIDs, itemNames) I get an output like: (None, <System.Int32[] at 0x43466c0>, <System.String[] at 0x43461c0>) Do I just need to figure out how to convert these back into python types?

IronPython vs. Python .NET

半城伤御伤魂 提交于 2019-11-29 18:59:06
I want to access some .NET assemblies written in C# from Python code. A little research showed I have two choices: IronPython with .NET interface capability/support built-in Python with the Python .NET package What are the trade-offs between both solutions? Reed Copsey If you want to mainly base your code on the .NET framework, I'd highly recommend IronPython vs Python.NET. IronPython is pretty much native .NET - so it just works great when integrating with other .NET langauges. Python.NET is good if you want to just integrate one or two components from .NET into a standard python application.

PythonNet FileNotFoundException: Unable to find assembly

亡梦爱人 提交于 2019-11-29 09:43:33
问题 I am trying to execute a Python script that uses Python For .Net (https://github.com/pythonnet/pythonnet) to load a C# library called "Kratos_3.dll" which is in the same folder as the script but the file cannot be found. I have installed clr using "pip install pythonnet". This is my script: import clr import sys sys.path.insert(0,"C:\\dev\\proj_1\\") clr.AddReference("Kratos_3") I keep getting the error FileNotFoundException: Unable to find assembly 'Kratos_3. at Python.Runtime.CLRModule