Ignoring windows registry PythonPath subkeys

Thomas Heller theller at ctypes.org
Fri Apr 4 13:49:24 CEST 2008


Floris Bruynooghe schrieb:
> Hi
> 
> We basically want the same as the OP in [1], i.e. when python starts
> up we don't want to load *any* sys.path entries from the registry,
> including subkeys of the PythonPath key.  The result of that thread
> seems to be to edit PC/getpathp.c[2] and recompile.
> 
> This isn't that much of a problem since we're compiling python anyway,
> but is that really still the only way?  Surely this isn't such an
> outlandish requirement?

If you look into PC/getpathp.c *and* PC/dl_nt.c, you'll find that the registry key name
if constructed from static components plus a variable component named PyWin_DLLVersionString.
The latter is loaded from a string resource (with resource ID 1000, IIRC) inside the pythonXY.dll.

This string resource can be changed (even without compiling!); so this is a way
for you to force the lookup of PythonPath to a different registry key.  You can choose
something that probably does not exist.

py2exe does this also for 'frozen' executables, and so has complete control
over sys.path.

Thomas




More information about the Python-list mailing list