如何从C ++调用lambdify(Sympy)?

时间:2016-06-30 14:51:47

标签: python c++ sympy python-c-api python-embedding

我试图使用Python / C API从C ++代码中调用Sympy的lambdify。代码粘贴在下面。

const char * file = "sympy";
const char * function = "lambdify";
Py_Initialize();
PyObject* pModuleString = PyString_FromString(file);
PyObject* pModule = PyImport_Import(pModuleString);
PyObject* pFunction = PyObject_GetAttrString(pModule, function);
PyObject* pargs = PyTuple_Pack(2,PyString_FromString("x,y"), PyString_FromString("x+y"));
PyObject* presult = PyObject_CallObject(pFunction, pargs);
Py_DECREF(pModule);
Py_DECREF(pModuleString);
Py_DECREF(pFunction);
Py_DECREF(pargs);
Py_Finalize();

PyObject * presult = blah 这一行显示以下错误

Exception AttributeError: "'NoneType' object has no attribute 'f_locals'" in <module 'threading' from 'C:\Anaconda2\Lib\threading.pyc'> ignored

请帮忙!

0 个答案:

没有答案