changing LD_LIBRARY_PATH for Python script

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Mar 29 13:15:28 EST 2000


> If I could only figure out the right strings to put in there :-).

If the problem is not finding the interpreter, but setting the
LD_LIBRARY_PATH, then you can also do the recursion in Python itself:

import os,sys,string
olpath = os.environ.get('LD_LIBRARY_PATH','')
if string.split(oldpath,':')[0] != "/tmp":
  path = "/tmp"
  if oldpath: path = path + ":" + oldpath
  os.environ['LD_LIBRARY_PATH'] = path
  os.execlp("python",sys.argv)

The test whether LD_LIBRARY_PATH already starts with /tmp will avoid
the recursion.

If you want to do it in /bin/sh, the following should work:

#!/bin/sh
true=0;
then=1;
fi=1;
if true :
	then
        # this adds an extra colon if LD_LIBRARY_PATH is not set
        LD_LIBRARY_PATH=/tmp:$LD_LIBRARY_PATH 
        export LD_LIBRARY_PATH
	exec python "$0" "$@"
fi

del true, then, fi

Hope this helps,
Martin




More information about the Python-list mailing list