使用Python从另一个文件夹导入模块,该文件夹将从同一文件夹导入模块
我有以下情况。 在“scripts”文件夹中,我有两个python脚本,“master”和“dependent”。Master从从dependent导入几个函数和类开始,以执行某些操作。例如:使用Python从另一个文件夹导入模块,该文件夹将从同一文件夹导入模块,python,import,module,Python,Import,Module,我有以下情况。 在“scripts”文件夹中,我有两个python脚本,“master”和“dependent”。Master从从dependent导入几个函数和类开始,以执行某些操作。例如: from dependent import blahblah #does a function or a class 我还有一个向上一级的脚本(在“scripts”文件夹所在的文件夹中),用于从master导入内容。事情是这样开始的 from scripts.master import whatev
from dependent import blahblah
#does a function or a class
我还有一个向上一级的脚本(在“scripts”文件夹所在的文件夹中),用于从master导入内容。事情是这样开始的
from scripts.master import whatever
但出现问题的原因是主导入依赖,我得到错误:
ModuleNotFoundError: No module named 'dependent'
如何修复此错误?也许您应该使用相对导入-从.dependent import blahblah使用类似点的
。问题在于,这只是一个示例,事实上,我在“脚本”中有相当多的文件相互导入。但我会尽量补充。到每个导入,看看它是否修复了它,所以建议编辑:是的,这修复了一切,tnx