下列的 例如,我创建了一个小hello.pyd库文件,其内容在此问题的结尾。

当我输入Python口译员时,我会得到以下内容:

D:\test\build\lib.win32-2.6>C:\Python26\python.exe
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
>>> hello.say_hello("Greg")
Hello Greg!
>>>

但是,使用Ironpython的解释器尝试这是错误的:

D:\test\build\lib.win32-2.6>"C:\Program Files (x86)\IronPython 2.7\ipy.exe"
IronPython 2.7 Alpha 1 (2.7.0.1) on .NET 4.0.30319.1
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named hello
>>>

如何使IPY解释器接受此C ++编译的库?


hellomodule.cpp

#include "C:\Python26\include\Python.h"

static PyObject* say_hello(PyObject* self, PyObject* args)
{
    const char* name;

    if (!PyArg_ParseTuple(args, "s", &name))
        return NULL;

    printf("Hello %s!\n", name);

    Py_RETURN_NONE;
}

static PyMethodDef HelloMethods[] =
{
     {"say_hello", say_hello, METH_VARARGS, "Greet somebody."},
     {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC

inithello(void)
{
     (void) Py_InitModule("hello", HelloMethods);
}

setup.py

from distutils.core import setup, Extension

module1 = Extension('hello', sources = ['hellomodule.cpp'])

setup (name = 'PackageName',
        version = '1.0',
        description = 'This is a demo package',
        ext_modules = [module1])

编译如下

python setup.py build -cmingw32
有帮助吗?

解决方案

您可以尝试使用 铁克拉德, ,但是最近没有看到太多工作。

其他提示

答案很可能是您的.pyd库不在Ironpython拾起它的正确路径上。由于您使用了Python,而不是Ironpython的设置工具,因此它可能是在PythonPath中建造和设置的,而不是Ironpython所需的位置。

解决方案是a。)更改Ironpython或b的路径。)在Ironpython的路径

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top