python.net

The definitive method to use NumPy and SciPy from IronPython

人走茶凉 提交于 2019-12-21 12:25:24
问题 There is a way to use NumPy/SciPy in IronPython, using IronClad to execute/communicate with the CPython binaries of the same. A newer project, Python Tools for VS allows for a faster integration with .NET IronPython programs because most of the NumPy/SciPy library functionality has been manually ported into IronPython. Comments on the same page point to this blogpost which links to github projects for the same. As of today (Oct 2012), what is the definitive method to integrate/use these 2

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

血红的双手。 提交于 2019-12-19 09:22:14
问题 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

Calling python code(.py files) from C#

大城市里の小女人 提交于 2019-12-18 04:53:17
问题 I have some python code that does a certain task. I need to call this code from C# without converting the python file as an .exe, since the whole application is built on C#. How can I do this? 回答1: If your python code can be executed via IronPython then this is definitely the way to go - it offers the best interop and means that you will be able to use .Net objects in your scripts. There are many ways to invoke IronPython scripts from C# ranging from compiling the script up as an executable

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

大城市里の小女人 提交于 2019-12-18 04:22:18
问题 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>,

How to install Python for .NET on Windows

时间秒杀一切 提交于 2019-12-17 10:41:46
问题 I downloaded Python for .NET. Inside the zip is clr.pyd , nPython.exe , Python.Runtime.dll and 2 debug database files. I put the clr.pyd and Python.Runtime.dll in my python DLLs dir C:\Python27\DLLs thinking this is all that's needed for installation. I then open up the Python GUI and type import clr and I get: Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> import clr SystemError: dynamic module not initialized properly New to python but not .NET and want to use

How to export C# methods?

一曲冷凌霜 提交于 2019-12-17 07:31:11
问题 How can we export C# methods? I have a dll and I want to use its methods in the Python language with the ctypes module. Because I need to use the ctypes module, I need to export the C# methods for them to be visible in Python. So, how can I export the C# methods (like they do in C++)? 回答1: Contrary to popular belief, this is possible. See here. 回答2: With the normal Python implementation ("CPython"), you can't, at least not directly. You could write native C wrappers around our C# methods

Python for .Net Error: ImportError: No module named

好久不见. 提交于 2019-12-12 10:13:38
问题 We are using Python for .Net to call .NET API built using C# from Python script. We are getting ImportError: No module named - error when an import is done as follows. Python script: import sys sys.path.append(r"C:\myfolderA\myfolderB") print sys.path import clr clr.FindAssembly(r"AA.BB.CC") clr.AddReference(r"AA.BB.CC") from AA.BB.CC.Api.DDInterface import DDClient On the above line I am getting following error Traceback (most recent call last): File "C:\myfolderA\myfolderB\testAPI.py", line

Python for .NET compilation for .NET3.5 and Python3.x

橙三吉。 提交于 2019-12-10 11:44:08
问题 Recently I've been working on a project which needs to use a .NET 3.5 Dll library, and the team is using Python3.x environment. So I went to the Python for .NET's github repo and downloaded the source code and tried compiling myself using Visual Studio 2013. In the source, there is a MVSC solution file named pythonnet , and I just opened the project and tried compiling Python.Runtime . By default, the Conditional compilation symbols is PYTHON27, UCS4 . So I changed it to PYTHON35, UCS2 to

How can I get generics to work in Python.NET with CPython

霸气de小男生 提交于 2019-12-10 10:33:13
问题 How can I get generics to work in Python.NET with CPython. I get an error when using the subscript syntax from Python.NET Using Generics TypeError: unsubscriptable object With Python 2.7.11 + pythonnet==2.1.0.dev1 >python.exe Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import clr >>> from System import EventHandler >>> from System import EventArgs >>> EventHandler

Python NET call C# method which has a return value and an out parameter

我只是一个虾纸丫 提交于 2019-12-09 23:08:15
问题 I'm having the following static C# method public static bool TryParse (string s, out double result) which I would like to call from Python using the Python NET package. import clr from System import Double r0 = Double.IsNaN(12.3) # works r1, d1 = Double.TryParse("12.3") # fails! TypeError: No method matches given arguments. This works in IronPython. d2 = 0.0 r2, d2 = Double.TryParse("12.3", d2) # fails! TypeError: No method matches given arguments Any idea? Update I found the following answer