问题标签 [python.net]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 在 Python(使用 Python.NET)中创建 C# Nullable Int32 以调用带有可选 int 参数的 C# 方法
我正在使用Python.NET加载 C# 程序集以从 Python 调用 C# 代码。这很干净,但是我在调用如下所示的方法时遇到问题:
Our.Namespace.Proj.MyRepo 中的一个方法:
我可以在存在可选的第三个参数但不知道为第三个参数传递什么以匹配空情况的情况下调用该方法。
iPython Notebook 表明最后一个参数应该是以下类型:
只是不确定如何创建一个匹配 Null 情况的对象。
有关如何创建 C# 识别的 Null 对象的任何建议?我假设通过本机 Python None 会起作用,但事实并非如此。
python - IronPython vs Python 速度与 numpy
我有一些 Python 源代码可以处理数字列表(比如大约 10,000 个浮点数)并对这些数字进行各种计算,例如包括很多 numpy.linalg.norm。
直到我们最近开始在 C# UI 中使用此代码(通过 IronPython 从 C# 运行此 Python 代码)之前,运行时间都不是问题。我提取了一组函数调用(按照第 1 段所述执行操作),发现与 Python 2.7 相比,此代码在 IronPython 中运行的时间大约是 Python 2.7 的 4 倍(这是在排除 C#/IronPython 中的启动/设置时间之后) . 我在来自 C# 的重复 IronPython 调用周围使用 C# 秒表,并在 Python 2.7 中的 execfile 周围使用 timeit 模块(因此 Python 时间结果包括更多操作,如加载文件、创建对象......而 C# 没有't)。前者大约需要 4.0 秒,而后者大约需要 0.9 秒。
你会期待这样的差异吗?有什么想法可以解决这个问题吗?其他的建议?
编辑:
这是一个简单的代码示例,它在我的机器上的 IronPython 上运行大约慢 10 倍(在 Python 2.7 中为 4 秒,在 IronPython 中为 40 秒):
python - 在 Win32 上的 Python 中使用 .NET?python.net 可行吗?
我正在尝试使用 python(我最熟悉的语言)编写一个快速而肮脏的小程序来轮询 WASP-B ANT+ 到 Windows 上的 wifi 网关。WASP-B 设备有一个未发布的 UDP 协议,它与 NDA 等混合在一起,但它们有一个已发布的用于 win32 编程的 .NET 库。所以......我搜索了一下,发现 IronPython 和 python.NET。如果我理解正确的话,IronPython 是一个 .NET 应用程序还是什么?不是我真正想要的,我只是希望能够在 python 程序中使用 WASP-B 的 .NET 库中的“东西”,所以我认为 python.NET 对我来说是更好的选择。
据我所知,python.NET 并不是那么活跃——这里有没有人知道它是否存在,它是否可以在 Windows 上与当前 (3.x) python 一起使用,以及我是否走在正确的轨道上?
在 sourceforge 上,python.NET 自 2013 年 1 月以来就没有被触及:
http://sourceforge.net/projects/pythonnet/
WASP,对于任何感兴趣的人:
c# - 使用 Python 访问 C# 库中的方法 - 互操作 .dll 文件
我有一个 .dll 文件(带有“Interop.”前缀),其中包含一个用 C# 编写的库。库中包含一个类、几个枚举、几个接口和几个委托。(通过使用 JetBrains dotPeek 反编译 .dll 来观察)
在此处查看 dll 结构:
我需要使用纯 Python 来访问类中的方法。我努力了:
但是,尝试调用“HtBrailleDriverClass”类中包含的任何方法会导致“AttributeError:未找到函数'initialize'”。我还尝试从它们的序数索引中访问它们:
但是,这会给出错误“AttributeError:未找到函数序数 1”。
是否有人能够阐明为什么我无法访问此 .dll 中的类以及为什么我也无法访问任何方法?
请记住,我必须使用纯 Python。
python - Python for .NET installation: Could not load file or assembly 'clr.pyd'
Really sorry guys! But for the life of me I am nearing the breaking point of going mad trying to install Python for .NET. I read the instructions meticulously below and still can't seem to get the installation to work. I am running python on an Spyder IDE, I a have windows 7. I downloaded the files pythonnet-2.0-Beta0-clr4.0_140_py27_UCS2_x86. I found my python directory by using the following commands:
I dragged all the unziped files into the directory and tried to load CLR
But I keep getting this error message. What am I doing wrong? Did a miss a step somewhere?
Here are the instructions I have been following: How to install Python for .NET on Windows
and
python - Python for .Net 错误:ImportError: No module named
我们正在使用 Python for .Net 从 Python 脚本调用使用 C# 构建的 .NET API。我们得到 ImportError: No module named - 导入完成时出错,如下所示。
Python脚本:
在上面的行中,我收到以下错误
没有其他信息可用于准确识别问题。来自同一项目的 15 天前构建的 Dll 可以正常工作。这个项目可能在两者之间经历了一些变化。
如何准确识别这个问题?
这可能是依赖问题吗?我尝试使用 JustDecompile 来比较旧的 dll 和新的 dll,但找不到任何异常。
非常感谢您的帮助。
谢谢,
python - Windows 7 32 位中用于 .net 的 Python
我正在尝试为 .Net 应用程序运行一个基本的 python。我安装了以下内容:
但是,每当我使用整数时,我都会收到以下错误。
例如: self.notifyIcon.ShowBalloonTip(1000) 和 timer.Interval = 60000 抛出以下错误
请在下面找到完整的程序:
python - Call IronPython from standard Python
How can I call an IronPython function from within Python? Is there an easy way to interface the two. I need the flexibility of both a full set of proper Python libraries that are not available in IronPython and the latest CLR which Python .net does not currently have.
What I've tried so far is to compile a IronPython dll but I can't get it to be loaded properly within Python.
My attempt to make IronPython n callable from Python
foo.py
compile_ipy.py
My attempt's to call Iron Python From Python
call_ipy_from_py1.py
call_ipy_from_py2.py
python - 在 Python 中使用 Python .Net 初始化 Array[int]
我正在使用Python .Net
图书馆,所以我无权访问List<T>
. 目前,当我尝试初始化 Array 时,会引发错误。
该文档有一个从最新代码库引发错误的示例。
前任:
以下适用于 64 位但不适用于 32 位!
python - 在 Python 中使用 Microsoft.Office.Interop.Excel 和 CLR 打印 Excel 文件?
我一直在寻找多种方法来打印 Excel 文件而不打开 Excel 应用程序,我在 C# 中使用了 Microsoft.Office.Interop.Excel,它工作得很好,所以我决定寻找一种方法让它也能在 python 中工作,我发现IronPython,但我只需要 python,然后我发现 pythonnet 可以使 .NET 程序集在 python 中工作。
问题是从源https://github.com/pythonnet/pythonnet安装它(或尝试) 它给了我一个关于未找到 Windows SDK 或其他东西的错误。
然后我通过pip安装了它并且安装成功,但是当我尝试导入或添加引用时显示另一个错误:
我已经从这里下载并安装了互操作程序集,因此应该安装它们。
我在这里找到了一种使用 IronPython 和 Interop dll打印 excel 文件的方法。
我的主要问题是我需要在不打开 Excel 应用程序的情况下打印一些 excel 文件,如果您有其他选择,欢迎
如果没有其他选择,我应该怎么做才能让它找到程序集?
附加信息:要在 C# 中打印,我使用了这个: