没有使用ironPython命名为ctypes的模块?

2024-05-14 16:57:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用IronPython2.6CTP for.NET4.0Beta2从C调用Python方法 我包括以下库:

IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.Debugging.dll
Microsoft.Scripting.dll

我正在调用的Python代码

^{pr2}$

C调用方法的代码:
eaHash(...)

ScriptEngine engine = Python.CreateEngine();
ScriptSource source = engine.CreateScriptSourceFromFile("EAHashingAlgorithm.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);

dynamic eaHash = scope.GetVariable("EAHashingAlgorithm");
dynamic hash = eaHash();
this.answer = hash.EAHash(_answer);

收到错误
ImportError: No module named ctypes


Tags: 方法代码answersourcedynamichashctpengine
2条回答

I keep getting the error there is no such module named as ctype...help anyone?

首先,这个模块叫做ctypes,而不是ctype。在

但是,更重要的是,ctypes在IronPython中直到2.6版才存在。在

这包括早期的2.6 Alpha,显然还包括.NET4的2.6CTP(从早期的alphas派生而来)。如果你想知道它是什么时候进入2.6版本的(测试版等等),那么这些信息可能会在某个地方找到,但是你真的不应该在意。使用最终版本2.6或更高版本。在

如果不能这样做,那么至少有一个第三方实现here可以使用。在

您需要确保IronPython标准库也可用,因为ctypes也需要一些纯Python文件。添加对指向库的engine.SetSearchPaths(new [] { "path/to/Lib" });的调用。如果您正在使用安装程序,它可能位于C:\Program Files\IronPython 2.7;在zip文件中,它位于Lib中。在

如果您正在分发和应用程序,那么使用与可执行文件相关的文件夹是最有意义的;Assembly.GetExecutingAssembly()可能对此很有用。在

相关问题 更多 >

    热门问题