So, it turns out that my problem is a simple case when the module search path is not set correctly during initialization from C ++.
In the Python introductory documentation:
On most systems (notably Unix and Windows, although the details are slightly different), Py_Initialize () computes the module's search path based on its best prerequisite for locating the standard Python interpreter, assuming the Python library found at a fixed location relative to the interpreter Python executable file. In particular, he searches for a directory named lib / pythonX.Y relative to the parent directory, where an executable called python is found in the path to the shell command (PATH environment variable).
So, this means that the module search path is in no way specified in the current working directory, but points to the python system installation folder.
The solution for me was to set the module search path correctly to indicate the current working directory. To do this, you need to initialize python, and then extract the sys.path value and add additional paths. Sorry to use boost if you don't; you should be able to easily see how to replace any required string.
Py_Initialize(); // now time to insert the current working directory into the python path so module search can take advantage // this must happen after python has been initialised boost::filesystem::path workingDir = boost::filesystem::absolute("./").normalize(); PyObject* sysPath = PySys_GetObject("path"); PyList_Insert( sysPath, 0, PyString_FromString(workingDir.string().c_str()));
radman
source share