Hey guys,
I have a C++ application and I want to embed sympy in it.
Application is statically linked against python.
However, I'm facing a problem when importing sympy module which simply
doesn't get imported.
Are there any examples on this?
Below is my code:
const char * python_home = "\"C:\\Program Files\\Python3.6.4\"";
int main(int argc, char *argv[])
{
PyObject *pName = nullptr;
PyObject *pModule = nullptr;
PyObject *pDict = nullptr;
PyObject *pFunc = nullptr;
PyObject *pValue = nullptr;
PyObject *pMainModule = nullptr;
Py_SetProgramName((wchar_t *) APP_NAME);
Py_Initialize();
Py_SetPythonHome((wchar_t *) python_home);
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append(\"C:\\Program Files\\Python3.6.4\")");
if(PyErr_Occurred()) {
// error handling
}
pName = PyBytes_FromString("sympy");
if(nullptr == pName)
{
// error handling
}
// Below function call always fails
pModule = PyImport_Import(pName);
if(nullptr == pModule)
{
PyObject *ptype, *ptraceback; PyObject *pystr = nullptr;
char *str;
PyObject *pErrMsg = nullptr; PyErr_Fetch(&ptype, &pErrMsg,
&ptraceback);
str = PyBytes_AsString(pystr); // str is always null
}
return 0;
}
I have Installed python and ran below command to install sympy:
pip3 install sympy
Dev Environment:
Qt_v5.9
Windows 7
Python_v3.6.4
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/94e74ce3-0158-46bd-b87c-60e6301f2533%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.