Pregunta

, he creado un pequeño archivo de biblioteca hello.pyd, los contenidos de las cuales se encuentran al final de esta pregunta.

Cuando entro pitón intérprete consigo el siguiente:

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!
>>>

Pero tratar esto con el intérprete de IronPython produce un error:

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
>>>

¿Cómo puedo hacer que el API intérprete aceptan esta biblioteca de C ++ compilado?


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])

Compilado como sigue

python setup.py build -cmingw32
¿Fue útil?

Solución

Se puede tratar de usar acorazado , pero no se ha visto mucho trabajo recientemente.

Otros consejos

Es muy probable que su biblioteca .pyd no está en el camino correcto para IronPython a recogerlo La respuesta. Dado que utilizó Python y no herramientas de configuración de IronPython, que probablemente tiene construida y puesta en marcha en el PYTHONPATH lugar de donde tiene que ser para IronPython.

La solución es a.) Cambiar su trayectoria para IronPython o b.) La reconstrucción en el camino de IronPython

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top