linux - Setting LD_LIBRARY_PATH from inside Python -


is there way set specify during runtime python looks shared libraries?

i have fontforge.so located in fontforge_bin , tried following

os.environ['ld_library_path']='fontforge_bin' sys.path.append('fontforge_bin') import fontforge 

and get

importerror: fontforge_bin/fontforge.so: cannot open shared object file: no such file or directory 

doing ldd on fontforge_bin/fontforge.so gives following

linux-vdso.so.1 =>  (0x00007fff2050c000) libpthread.so.0 => /lib/libpthread.so.0 (0x00007f10ffdef000) libc.so.6 => /lib/libc.so.6 (0x00007f10ffa6c000) /lib64/ld-linux-x86-64.so.2 (0x00007f110022d000) 

your script can check existence/properness of environment variable before import module, set in os.environ if missing, , call os.execv() restart python interpreter using same command line arguments updated set of environment variables.

this advisable before other imports (other os , sys), because of potential module-import side-effects, opened file descriptors or sockets, may challenging close cleanly.

this code sets ld_library_path , oracle_home:

#!/usr/bin/python import os, sys if 'ld_library_path' not in os.environ:     os.environ['ld_library_path'] = '/usr/lib/oracle/xx.y/client64/lib'     os.environ['oracle_home'] = '/usr/lib/oracle/xx.y/client64'     try:         os.execv(sys.argv[0], sys.argv)     except exception, exc:         print 'failed re-exec:', exc         sys.exit(1) # # import yourmodule print 'success:', os.environ['ld_library_path'] # program goes here 

it's cleaner set environment variable part of starting environment (in parent process or systemd/etc job file).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -