How do I resolve sys.path differences in Python and IronPython -
i running pathing issues scripts wrote test parsers i've written. appear python (27 , 3) both not act ironpython when comes using current working directory part of sys.path. result inner package pathings not work.
this package layout.
mypackage __init__.py _test __init__.py common.py parsers __init__.py _test my_test.py
i attempting call scripts within mypackage directory.
command line statements:
python ./parsers/_test/my_test.py
ipy ./parsers/_test/my_test.py
the import statement located in my_test.py file is.
from _test.common import testclass
in python scenario mypackage/parsers/_test directory appended sys.path result mypackage cannot found. in ironpython scenario both mypackage/parsers/_test directory , mypackage/ in sys.path. same bad reference if called test within _test directory (it have no idea mypackage). if consolidated test files _test directory still have pathing issue.
i should note, tested , if did like
import sys import os sys.path.append(os.getcwd())
it load correctly. have every single file.
is there anyway fix kind of pathing issue without doing following.
a. appending relative pathing sys.path in every file.
b. appending path include mypackage (i not want package part of python "global" system pathing)
thanks alot tips!
two options spring mind:
use environment variable pythonpath , include .
add sys.path @ beginning of program
import sys.path sys.path.append('.')
- if need import relative path dynamically can
import somemodule import sys dirname = os.path.dirname(os.path.abspath(somemodule.__file__)) sys.path.append(dirname)
Comments
Post a Comment