【发布时间】:2021-12-30 05:49:37
【问题描述】:
我的home/file.py 中有一个def hello() 函数。我创建了一个home/common/utils.pyfile 并将函数移到那里。
然后我像这样导入它:from utils import hello 并且我的文件中的导入不会引发错误。
该路径也自动添加到我的 settings.json 中:
"python.analysis.extraPaths": [
"home/common"
]
但是,当我运行代码时,它显示Runtime.ImportModuleError: Unable to import module 'file': No module named 'utils'
那么创建 utils 模块的正确方法是什么?
【问题讨论】:
-
您现在导入的文件是什么?您的模块目录结构如何?你如何执行代码?你执行哪个模块?
-
我在
home/file.py中进行导入。我在home/common/utils.py中创建了另一个文件夹。我在 aws lambda 中执行代码(file.py)。 @DariuszKrynicki
标签: python python-3.x file import fileutils