发生异常: ImportError attempted relative import with no known parent package
时间: 2023-10-17 09:26:20 浏览: 87
在Python中,当你使用相对引用方式(例如import ...module)去引用包时,如果没有已知的父包,就会出现ImportError: attempted relative import with no known parent package异常。这个异常的原因是Python解释器无法解析相关模块的相对路径导入。具体来说,当你的脚本中使用了相对导入方法,并且没有明确指定父包,就会触发这个异常。这个异常通常会显示出错的行数,提示你在代码的第几行出现了相对导入问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Python报错:ImportError: attempted relative import with no known parent package](https://blog.csdn.net/m0_45521766/article/details/126513067)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [【ImportError】: attempted relative import with no known parent package](https://blog.csdn.net/ybw_2569/article/details/98775794)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文