Original Post
So I'm trying to embed python in a C++ application I'm writing. I'm trying to change python's path so it will find some modules I wrote but I can't seem to change the path. The code is here: The code just grabs the old path and then concatenates the path I want to add, in this case ":../Resources". When I print the variable 'newPath' it shows my addition. However when I check with Py_GetPath(), it shows the old path without my addition. I have no clue why not, does anybody have any ideas? I've included the output of the program below for reference.
#include <Python.h>
#include <string>
int main(int argc, char *argv[]) {
Py_Initialize();
const char* oldPath = Py_GetPath();
char* newPath = new char[strlen(oldPath)+256];
strcpy(newPath, oldPath);
strcat(newPath, ":../Resources");
printf("Path: %s\n", newPath);
PySys_SetPath(newPath);
printf("Path: %s\n", Py_GetPath());
delete newPath;
Py_Finalize();
return 0;
}
Path: /Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload:
../Resources
Path: /Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload