Domanda

A seguito di questo esempio , ho creato un piccolo file di libreria hello.pyd, i cui contenuti sono alla fine di questa questione.

Quando entro interprete Python ottengo il seguente:

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

Ma cercare questo con l'interprete di IronPython produce un errore:

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

Come posso fare IPY interprete accettare questa libreria C ++ compilato?


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

Compilato come segue

python setup.py build -cmingw32
È stato utile?

Soluzione

Si può provare a utilizzare Ironclad , ma non ha visto molto lavoro da poco.

Altri suggerimenti

La risposta è più probabile che la libreria .pyd non è nel percorso corretto per IronPython per raccoglierlo. Dal momento che si è utilizzato Python e non strumenti di configurazione di IronPython, probabilmente ottenuto costruito e di installazione nella PYTHONPATH, piuttosto che dove deve essere per IronPython.

La soluzione è quella di un.) Modificare il percorso per IronPython o b.) Ricostruire nel percorso di IronPython

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top