You need to call PySys_SetArgv(int argc, char **argv, int updatepath)
for the relative imports to work. This will add the path of the script being executed to sys.path
if updatepath
is 0
(refer to the docs for more information).
The following should do the trick
#include <Python.h>
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PySys_SetArgv(argc, argv); // must call this to get sys.argv and relative imports
PyRun_SimpleString("import os, sys\n"
"print sys.argv, \"\\n\".join(sys.path)\n"
"print os.getcwd()\n"
"import thing\n" // import a relative module
"thing.printer()\n");
Py_Finalize();
return 0;
}