问题描述
对于一个项目,我需要在Python中包含一个DLL。我正在使用CPython3.4,并使用pythonnet clr模块(pythonnet-2.0.0.dev1-cp34-none-win_amd64.whl)来包含dll。在dll中,我需要一个可以让我不断更新测量值的函数。 dll是用VB.net编写的,我需要的功能如下所示:
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
这是我在python中编写的用于调用此函数的代码:
This is the code that I have written in python to call this function:
import clr
clr.AddReference('dll name')
from dll import SetupMonitor
monitor = SetupMonitor(None, None, None)
# call to the dll function
# Everytime the measurement is changed the "test" function should be executed
monitor.AdviseStart(8, test)
def test(data):
print("Value: " + str(data))
我想使用Python3.4而不是Ironpython的项目。
我在python3.4和2.7中测试了此代码,但出现此错误:
For the sake of my further project I want to use Python3.4 and not Ironpython.I tested this code in python3.4 and 2.7 and I got this error:
No method matches given arguments
我100%确信该错误来自AdviseStart函数。因为当我在IronPython中使用相同的代码时,它可以工作。在Ironpython中,此代码给出了我期望的输出:
I am 100% sure that the error is from the AdviseStart function. Because when I use the same code with IronPython it works. In Ironpython this codes gives the output I expect:
Value: -74
此函数的目标是每次进行新测量时,都会调用函数 test。测量和调用的所有内容都在dll中。无论如何,我可以使此函数在任何CPython版本中工作吗?
The goal of this function is that everytime a new measurement is made the function "test" will be called. Everything for the measurement and calling is in the dll. Is there anyway I can make this function work in any CPython version?
推荐答案
64位整数参数存在一些问题建立。据我所知,特定的问题已经解决,但是那是在您使用的构建版本发布之后。
There were some problems with integer arguments in the 64 bit builds. As far as I know that particular problem has been solved, but it would have been after that build you are using was released.
尝试从github(),然后进行构建。要构建和安装它,您只需运行 python setup.py install(或任何常用的setup.py命令)。
Try getting the source from github (https://github.com/renshawbay/pythonnet) and build that instead. To build and install it you just run "python setup.py install" (or any of the usual setup.py commands).
如果仍然无法正常工作,可以通过在setup.py中设置CONFIG = Debug并重建来构建调试版本。然后,您将能够将Visual Studio调试器附加到python进程,并逐步执行python.net代码,以查看查找到的签名以及为什么它与调用它的参数不匹配。
If it still doesn't work you can build a debug version by setting CONFIG="Debug" in setup.py and rebuilding. You will then be able to attach the visual studio debugger to your python process and step through the python.net code to see what signatures it's finding and why it's not matching with the arguments you're calling it with.
这篇关于调用dll函数在IronPython中起作用,在CPython3.4中不起作用,给出“没有方法匹配给定参数”。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!