[Distutils] Windows Python sys.prefix

Mark Hammond mhammond at skippinet.com.au
Wed Sep 19 00:42:45 CEST 2007

> How does Python on Windows determine sys.prefix?

By consulting the registry.  The main use-case for that is when Python is
embedded in another executable - often, but not always, via COM.  When
Python is hosted inside excel.exe, for example, its impossible to calculate
sys.path or sys.prefix based on that executable.  In that same example,
Python's DLL will have been loaded from a directory on the global PATH,
which generally means the \Windows\System32 directory - so that too is no
help in calculating the path.

[IIRC, Python actually tries to use the executable to locate its 'landmark'
and only falls back to the registry when that fails - but that sounds
exactly like what is happening in your example.  The gory details are in

> Is there a way to effect that?

Setting PYTHONHOME in the environment is the only way I'm aware of.



More information about the Distutils-SIG mailing list