is there way programmatically replace pythonpath ? should add want run decode.py spark-submit
i have following directory structure @ 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 copied crfsuite/crfsuite.py , crfsuite/_crfsuite.so local directory (where decode.py exists), following works:
ld_library_path=./crfsuite python decode.py
is there way programmatically add .py , .so files? came 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
pythonpath
env. variable contents copied in sys.path
module, before importing can add paths instance:
import sys sys.path.append("/path/to/your/module") # your_module.py found in /path/to/your/module import your_module
note can remove paths using sys.path.remove
if pythonpath
overrides system lib , don't want to.
Comments
Post a Comment