In a __init__.py
file of a package, I imported several files relying on a third party module in another path. To inform python of the path of the third party module, I add the path to sys.path
, like this
# __init__.py
import sys
sys.path.append("path of the third party module")
from .file_in_the_package import ... # the file rely on the third party module
Every thing goes fine until I moved the sys.path.append
to a separated file in the package, like this
# separated file imp.py
import sys
sys.path.append("path of the third party module")
# changed __init__.py
import imp
from .file_in_the_package import ... # the file rely on the third party module
in which the added "path of the third party module"
can not be found in either __init__.py
or file_in_the_package.py
.
However, things goes fine with from .imp import *
.
Now, I'm just curious that in what situation the changed sys.path
will be passed when import a file/package with sys.path
changed?