[Tutor] Set LD_LIBRARY_PATH and equivalents platform-independently

eryksun eryksun at gmail.com
Sat Jan 19 16:09:16 CET 2013


On Sat, Jan 19, 2013 at 7:24 AM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
>
> But is Windows the only exception in the way that libraries are dealt with?
> Or do DLLs also have a dynamic area?

DLLs can have an embedded manifest. To solve the DLL Hell problem,
Windows introduced side-by-side assemblies (WinSxS):

Everything you Never Wanted to Know about WinSxS
http://omnicognate.wordpress.com/2009/10/05/winsxs

> So if, at runtime, I do something evil like del os.environ['PATH'] in
> Windows this actually deletes/propagates to my path?? Unlike other OS
> where os.environ is 'just' a dict that contains the paths, that once loaded,
> cannot be modified (well you can modify them, but the OS won know about the
> changes).

That would only unset PATH for your current process, not the parent
process, and not your user profile or system PATH. The latter are set
in the registry (i.e. you need to use _winreg/winreg). If putenv is
supported, os.environ uses it.

That point about Windows PATH is that LoadLibrary evaluates it for
each call. That means you can modify it in Python before calling CDLL.
In Linux, ld.so caches the value of LD_LIBRARY_PATH when the process
starts; it can't be set in Python before calling CDLL. You have to
inherit it from the parent process or explicitly set it in bash/Python
script (e.g. os.fork followed by os.execle with a modified
environment).


More information about the Tutor mailing list