setting environment variables
Walter Hofmann
wh at msgto.com
Mon Jun 19 15:04:47 EDT 2000
Hi,
I need to set an environment variable so that a python module which I'd
like to use finds the right shared library.
I'm using Linux, so doing
LD_LIBRARY_PATH=/opt/kde2/qt/lib python test.py
works. But I would prefer to do it in python so that one can start my
program by entering
./test.py
However, setting LD_LIBRARY_PATH with os.environ within the python
script (but before importing the library) is too late. The dynamic
linker will not find the library this way.
I then tried to use
#!/usr/bin/env LD_LIBRARY_PATH=/opt/kde2/qt/lib python test.py
which, according to env's manpage should work. It doesn't, but hangs
instead in a tight loop consoming 100% CPU. Neither works the more
complex
#!/bin/bash -c 'LD_LIBRARY_PATH=/opt/kde2/qt/lib python ./test.py'
which gives
wh at frodo:~/programming/qtpython > ./test.py
bash: - : unrecognized option
Usage: bash [GNU long option] [option] ...
[...]
Finally, I found out that the following rather tricky (dual language)
code works, however it is ugly to say the best:
#!/bin/sh
LD_LIBRARY_PATH="/usr/lib/qt-2.1.1/lib" "exec" "python" "$0" "$*"
del LD_LIBRARY_PATH
# python code starts here
My question:
Is anyone on this list aware of a cleaner way to to this?
Walter
More information about the Python-list
mailing list