Embedding Python: How To Hardwire Module Search Path

Warren Postma embed at geocities.com
Fri Apr 7 15:18:49 CEST 2000

> Does anybody know what to do prior to Py_Initialize(). Or am I
> completely wrong?
> PySys_SetPath() crashes when called before Py_Initialize().

First just set the environment variable PYTHONPATH, but if you want to have
it ignore the registry on Windows, I think you may have to resort to
modifying source code.

I did this. Look for registry code in import_nt.c. Email me if you want to
see what I did, but since they are trivial you can probably do it yourself.

My modified version ignores the registry, uses the PYTHONPATH, as well as
certain 'hardcoded' sensibiel defaults such as looking in the Lib
subdirectory from wherever your program is running from for the 'site.py'
and 'exceptions.py' modules. From there, set up your additional module
search paths in the PYTHONPATH environment variable.


More information about the Python-list mailing list