Is there a way to programmatically replace PYTHONPATH ? I should add that I want to run decode.py with spark-submit
I have the following directory structure at some-path:
decode.py
decode2.py
crfsuite/
crfsuite.py
_crfsuite.so
libcqdb-0.12.so
libcrfsuite-0.12.so
decode.py:
import crfsuite
if __name__ == '__main__':
tagger = crfsuite.Tagger()
The following command works:
PYTHONPATH=./crfsuite LD_LIBRARY_PATH=./crfsuite python decode.py
Or if I copied crfsuite/crfsuite.py and crfsuite/_crfsuite.so to my local directory (where decode.py exists), then the following also works:
LD_LIBRARY_PATH=./crfsuite python decode.py
Is there a way to programmatically add .py and .so files? I came up with decode2.py:
from ctypes import *
import imp
if __name__ == '__main__':
cdll.LoadLibrary('<some-path>/crfsuite/_crfsuite.so')
imp.load_source('crfsuite', '<some-path>/crfsuite/crfsuite.py')
tagger = crfsuite.Tagger()
Executing:
LD_LIBRARY_PATH=./crfsuite python decode2.py
Traceback (most recent call last):
File "decode2.py", line 6, in <module>
imp.load_source('crfsuite', '<some-path>/crfsuite/crfsuite.py')
File "<some-path>/crfsuite/crfsuite.py", line 17, in <module>
_crfsuite = swig_import_helper()
File "<some-path>/crfsuite/crfsuite.py", line 16, in swig_import_helper
return importlib.import_module('_crfsuite')
File "sw/anaconda2/lib/python2.7/importli/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named _crfsuite
sys.path.add('<some-path>/crfsuite')?appendorinsert.sys.pathis not aset, it is alist.appendof course.sys.path.append('<some-path>/crfsuite')