问题标签 [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.

0 投票
0 回答
89 浏览

python - windows8的.net问题的python(可能)

我成功地使用 python for .net 连接 VB 代码(即编译的 .dll)但是最近我使用 windows8 的客户端报告了我们位于的奇怪问题,import clr 这就是我所说的:

而 clr 是:

在众多 windows7 机器上一切正常,但在 win8 中我得到了这个:

错误信息

似乎并非所有库都被导入并且它在字典中失败(无论如何我都会避免并坚持基本数据类型:))

你有什么线索吗?提前致谢!

0 投票
0 回答
341 浏览

python - python脚本作为模板将json文件解析为python对象

我真的是 python 新手,想编写一个 python 脚本,通过读取 json 文件来创建 python 对象。

我只想将 json 文件名作为参数传递给脚本。我想使用这个 python 脚本作为模板来解析 json 文件。下面是我的示例 json 文件内容

上面的示例文件非常小。我可能需要解析一个非常大的 json 文件。

谢谢,

0 投票
1 回答
695 浏览

python - 使用 python.net 自动化 windows 窗体对话框

我正在 python.net 中编写一个事件处理程序,当弹出一个对话框并且我希望事件处理程序回答对话框时调用这个事件处理程序。

我想知道是否有办法从 Dialog 对象本身(类似于 args.Dialog.DialogResult='OK' 等)中回答 windows 窗体对话框,还是我必须求助于模拟人类交互(即 - 将对话框带到前面,定位按钮坐标并模拟鼠标点击)。

我附上了我用来处理事件的示例代码(来自 Agilent - http://nbviewer.ipython.org/github/jonnojohnson/Agilent/blob/master/Python_Automation/N5990A_Python_Automation.ipynb):

0 投票
1 回答
1256 浏览

c# - 如何使用 Python for .NET 正确嵌入

当我尝试使用

尝试加载依赖项中的一些可选模块(在没有嵌入的情况下使用模块不需要)。这会导致此方法返回 null,因为其中一些可选依赖项不是必需的,因此不可用。在此 PythonNET API 中用于加载依赖于多个其他模块的用户编写模块的正确方法是什么?

0 投票
1 回答
2473 浏览

c# - Pythonnet:如何使用嵌入式 Python 解释器?

我正在尝试使用 pythonnet 使用来自 C# 的嵌入式 python 解释器(在https://github.com/renshawbay/pythonnet找到的 python3 兼容版本)

我的解释器位于 D:\src\scratch\TestPythonNet\TestPythonNet\PythonRuntime 并具有来自 python 发行版的“Lib”和“Libs”文件夹。

我已经使用以下代码进行了测试:

但是,它不起作用。我得到一个“SystemError:PyEvalCodeEx:NULL globals”。每次我尝试从 python 获取对象时,代码都会失败。

我究竟做错了什么?

0 投票
1 回答
1850 浏览

c# - Python for .Net:运行嵌入式解释器

0 投票
1 回答
140 浏览

c# - 创建密封通用委托的具体版本

我想做以下事情:

我不能这样做,因为 EventHandler<> 是密封的。有谁知道我可以用来制作 EventHandler<> 的具体版本的解决方法?我需要这个,因为我怀疑 Python.NET 无法将 EventHandler<> 作为方法参数处理。

更新:

基本上,我想这样做:

这样以后我可以这样做:

我想这样做的原因是因为我怀疑它会为我在 Python.NET 中使用这个库时遇到的问题提供一种解决方法。

0 投票
1 回答
3671 浏览

python - PyInstaller and PythonNet CLR

ok, I need some help with pyinstaller and PythonNet.

This is my first time posting to the forum and I'm relatively inexperienced with coding but I've been learning a little python for GUI development. I've got a script that uses a .NET dll library to interface with a USB camera. The script runs properly in Python, but I'm trying to compile it to .exe via Pyinstaller and I'm getting stuck.

Here are the first few lines of code:

And here's the error after running the compiled .exe file:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembl y 'Python.Runtime, Version=4.0.0.1, Culture=neutral, PublicKeyToken=5000fea6cba7 02dd' or one of its dependencies. The located assembly's manifest definition doe s not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String cod eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntro spection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String code Base, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& s tackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntros pection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as semblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMar k& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIn trospection, Boolean suppressSecurityChecks) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at clrModule.initclr()

I think the issue with python.runtime is similar to the one posted here (https://github.com/pythonnet/pythonnet/issues/34) but I've tried the recommended solution and I'm still getting the same error. i.e. I uninstalled pythonnet and then searched for and deleted any remaining clr.pyd or python.runtime.dll files. Then re-installed using pip via the command prompt:

"pip install --pre pythonnet"

After compiling my script, python.runtime.dll appears in the "dist" folder along with the exe file. But there's something weird going on with the version numbers. Right clicking the dll and viewing "properties" in windows lists the version as 2.0.0.2, but viewing the assembly info (with dotPeek) for the same file it is listed as 4.0.0.1. What's going on here?

Here are the screenshots showing the version discrepancy:

dll assembly screenshot shows version 4.0.0.1

[windows properties screenshot showing version 2.0.0.2]

imagizer.imageshack.us/v2/381x520q90/902/6DEzLM.jpg (sorry, I can't make this one a link)

Please note I'm running Python 2.7 (32-bit) on Windows 7 (64-bit). Also, initially I got an error during compiling because Pyinstaller couldn't find the python.runtime.dll needed by CLR, but I modified the clr-hook.py to include the full dll path, so now it compiles without error but something is still clearly not right. Here's the new hook:

And here's the output of pyinstaller during compilation:

0 投票
1 回答
295 浏览

c# - 将不同的参数传递给 c# 动态库

我在 CPython 中使用 pythonnet,我设法安装它

确实有效。

在我的 C# 代码中,如果成员

如果我现在尝试做(在 Python 中):

它总是抱怨并说:

为什么?

0 投票
4 回答
22466 浏览

python - ImportError: 使用 python.org 的 CPython 时没有名为 clr 的模块

我正在编写应该在下面调用 python 脚本的 C++ 代码。为此,我使用 python.org 的cpython。一些 python 脚本在 python for .net 的帮助下执行 .net 代码,而当涉及到 .net 时,这一切都失败了。我尝试构建测试应用程序以验证它失败的地方,发现它无法导入 clr 模块。

当我运行此代码时,它给了我 ImportError: No module named clr

如果我去 python 控制台并输入“import clr”,一切正常。我还检查了 sys.path,它包含 clr.pyd 所在的文件夹“C:\Python27\DLLs”。我还尝试通过以下方式在 C++ 中设置此路径:

但这没有帮助。另外我不明白为什么 clr 模块显示为 clr.pyd 而不是 .pyc 像其他编译模块一样。

有人可以解释为什么 import clr 通过 CPython 失败?有可能让它工作吗?