admin管理员组文章数量:1334677
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?
本文标签: in pythonwhat is the passing logic of syspath while importing a file or packageStack Overflow
版权声明:本文标题:In Python, what is the passing logic of `sys.path` while importing a file or package? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742366685a2461427.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论