I am writing a quite large Python application; the application is actually to a large part a wrapping of several shared libraries written in C and C++(Qt). I am 'installing' this without administrator rights, so everything including shared libraries, binary and also Python modules must be in non-standard locations, i.e. I have a situation like this:
The whole thing is distributed as open source, and I need to find a reasonably elegant and simple way to set the necessary environment variables. The whole thing is distributed with version control software; so the environment variables must be set in some 'local addition' i.e. something like:
#!/bin/bash
export LD_LIBRARY_PATH /funny/path/lib:$LD_LIBRARY_PATH
export PYTHONPATH /funn/path/python/lib:$PYTHONPATH
#
exec python main.py
But I am programming in Python for a reason - I detest these shell scripts. Any views on the most elegant way to do this would be nice.
Joakim
Why waste time detesting shell scripts?
Since you won't install in a standard location, (and can't seem to get sys admins to install needed packages in standard locations) that's almost your only alternative.
You can set the PYTHONPATH
from within Python. It's in sys.path
. Setting an environment variable (like LD_LIBRARY_PATH
) is harder, because Linux limits the ways in which applications can change the environment.
You can use os.exec
to run a process in a modified environment. It's a little odd using Python to then do os.exec..e()
to invoke Python, but it is an easy way to set an additional environment variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With