'attempted relative import with no known parent package'
时间: 2023-10-17 11:26:22 浏览: 68
Python 从相对路径下import的方法
'attempted relative import with no known parent package'这个错误意味着在没有已知父包的情况下尝试进行相对导入。解决这个问题的方法是修改路径。你可以从你的主模块开始进行导入,然后使用绝对导入或相对导入来引用其他模块。比如,如果你的主模块是deep_sort,你可以使用以下方式进行导入:
- 绝对导入:`from package import module`
- 相对导入:`from .subpackage import module`
这样,你就可以避免这个错误并成功进行导入了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Python 从相对路径下import的方法](https://download.csdn.net/download/weixin_38622227/14862573)[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: 33.333333333333336%"]
- *2* [【一分钟解决】Python报错ImportError: attempted relative import with no known parent package](https://blog.csdn.net/weixin_43958105/article/details/114012590)[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: 33.333333333333336%"]
- *3* [attempted relative import with no known parent package,已解决](https://blog.csdn.net/weixin_47037450/article/details/129618388)[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: 33.333333333333336%"]
[ .reference_list ]
阅读全文