Python 3中的相对导入 - Relative imports in Python 3

问题:

I want to import a function from another file in the same directory. 我想从同一目录中的另外一个文件导入函数。 dom

Sometimes it works for me with from .mymodule import myfunction but sometimes I get a: 有时它与from .mymodule import myfunction对我from .mymodule import myfunction但有时我获得: ide

SystemError: Parent module '' not loaded, cannot perform relative import

Sometimes it works with from mymodule import myfunction , but sometimes I also get a: 有时它与from mymodule import myfunction ,但有时我也获得: 函数

SystemError: Parent module '' not loaded, cannot perform relative import

I don't understand the logic here, and I couldn't find any explanation. 我不了解这里的逻辑,也找不到任何解释。 This looks completely random. 这看起来彻底是随机的。 this

Could someone explain to me what's the logic behind all this? 有人能够向我解释全部这些背后的逻辑是什么? spa


解决方案:

参考一: https://stackoom.com/question/19Flx/Python-中的相对导入
参考二: https://oldbug.net/q/19Flx/Relative-imports-in-Python-3
相关文章
相关标签/搜索