process-isolation
process-isolation copied to clipboard
importing local modules
I have a project with a file structure as follows:
my_project
__init__.py
my_code.py
lib
__init__.py
my_lib.py
If I run the following code, everything works just fine:
import lib.my_lib as my_lib
... do something with my_lib ...
However, if I try to do the following I get an error:
from process_isolation import import_isolated
my_lib = import_isolated('lib.my_lib')
... do something with my_lib ...
I get the error:
ImportError: No module named lib.my_lib
How do I make this work? Thanks...
I was able to get this working with the following. I figured I would post back with the solution I found for everyone's benefit...
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/lib')
from process_isolation import import_isolated
my_lib = import_isolated('my_lib')
... do something with my_lib ...
This explicitly adds my lib to the system path since it does not appear that local modules are picked up by this code. This is a valid workaround from what I can tell...