I'm trying to run a Python script in a C++ program using Python.h. Because this C++ program can be installed (make install) in /usr/bin, it needs to be able to find the Python script both in its own directory (in case it was not installed) or in one of the PATH environment variable's directories.
I have tried doing :
PyObject *pName = PyString_FromString(scriptName); // scriptName is "file.py" as a char*
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append(\".\")");
PyObject *pModule = PyImport_Import(name); // not working because absolute path only
//since Python 2.7 ?
and
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append(\".\")");
PyObject *pModule = PyImport_ImportModuleEx(scriptName, NULL, NULL, NULL);
But both leave me with pModule == NULL after this call but work if I run the C++ module from its own directory.
Thanks a lot for your help
makeputs the C++ executable in the same directory where the Python script is located.make installcopies both the C++ executable and the Python script inusr/bin(or wherever the user wants to install those). 2) I have not, mostly because this part of the C++ program is pretty far away from themainand thus of the originalargcandargvvariables. Do I need to do that to set the application path ?