PYTHONPATH and embedding python
Ignacio Vazquez-Abrams
ignacio at openservices.net
Tue Oct 9 22:30:03 EDT 2001
On Tue, 9 Oct 2001, Idriz SMAILI wrote:
> I have the following problem:
>
> I have embedded Python in an C++ application. The Python modules are
> after freezing integrated in the application and those modules should be
> imported as frozen modules. Before I initialize the Python interpreter
> I've used the putenv in C code to set the environment variable
> PYTHONPATH to "pwd == .". I've used the getenv function to check if the
> environment variable has been changed and it is as expected really
> changed to the new setting result. The problem is that the Python
> Interpreter during its initialization uses the same getenv function and
> it gets the old value of the PYTHONPATH value. This is my problem,
> because I've got a lot of problems in case the user has installed a
> different python version, because the Python Interpreter tries to import
> for example the os module, which is different between Python 1.5.2 and
> Python 2.1.1. I am using Python 2.1.1 and Microsoft Visual Studio V.
> 6.0. under WinNT operating system.
>
> Does anyone have any suggestions? Thanks.
Use this bit of code right after Py_Initialize():
---
char *path, *newpath;
path=Py_GetPath();
newpath=strcat(path, ":."); // or ";.", possibly
PySys_SetPath(newpath);
free(newpath);
---
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list
mailing list