Python uses the PYTHONPATH
environment-variable to determine in which folders it should look for modules.
You can play around with it by modifying sys.path
, which works nicely for pure Python-Modules.
But when a module uses shared object files or static libraries, it looks for those in LD_LIBRARY_PATH
(on linux), but this can't be changed as easily and is platform dependent as far as I know.
The quick-fix for this problem is of course to set the environment-variable or invoke the script like LD_LIBRARY_PATH=. ./script.py
, but then you'll have to set it again for every new shell you open.
Also, the .so
files in my case will always be in the same directory as the .py
file, but may very well be moved to another absolute path, so I'd like to set them automatically every time I invoke the script.
How can I edit the path in which the Python interpreter looks for libraries platform-independently on runtime?
EDIT:
I already tried os.environ['LD_LIBRARY_PATH'] = os.getcwd()
, but to no avail.
.so
or.a
but.dll
and.lib
-files, and my libraries will have to be re-compiled for it one way or another. I just felt like a quick-and-dirty solution would ease testing and development. – Uncork