> Subject: Re: [Tutor] Set LD_LIBRARY_PATH and equivalents > platform-independently
> > On 01/16/2013 07:05 PM, Alan Gauld wrote: >> On 16/01/13 21:06, Albert-Jan Roskam wrote: >> >>> Is there a builtin function that can set LD_LIBRARY_PATH or equivalents >>> platform-independently? >> >> No. >> But there is putenv() in the os module. >> But how well it works across OS I'm not sure. >> > > I don't recall enough about Windows to be sure whether putenv would > work, but the environment variable Windows uses to search for DLL's is > certainly not LD_LIBRARY_PATH Hi Alan, Dave, Thanks for your replies. os.putenv() may be easier than os.environ because, hopefully, it takes care of the OS-specific separators of the values (";" for Windows, ":" for Linux, others I don't know but I'd guess they're all ":"). Then again, this sentence from the Python page is a little worrying: "*If* the platform supports the putenv() function, ...". (emphasis added). But os.environ has its own problems: "On some platforms, including FreeBSD and Mac OS X, setting environ may cause memory leaks. Refer to the system documentation for putenv()." Hmmmm. As an alternative, I used os.chdir to tell the OS where to start looking for libraries, but somebody on this list (I forgot who) warned me that this could have nasty side effects. http://docs.python.org/2/library/os.html os.environ A mapping object representing the string environment. For example, environ['HOME'] is the pathname of your home directory (on some platforms), and is equivalent to getenv("HOME") in C. This mapping is captured the first time the os module is imported, typically during Python startup as part of processing site.py. Changes to the environment made after this time are not reflected in os.environ, except for changes made by modifying os.environ directly. If the platform supports the putenv() function, this mapping may be used to modify the environment as well as query the environment. putenv() will be called automatically when the mapping is modified. Note. Calling putenv() directly does not change os.environ, so it’s better to modify os.environ. Note. On some platforms, including FreeBSD and Mac OS X, setting environ may cause memory leaks. Refer to the system documentation for putenv(). If putenv() is not provided, a modified copy of this mapping may be passed to the appropriate process-creation functions to cause child processes to use a modified environment. Regards, Albert-Jan _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor