先在讨论python导入问题时,先弄清楚几个重要概念和区别:

如果急于看解决方案直接跳到第七点,推荐读完

一、什么是模块,什么是脚本(script vs module)
python包导入细节(attempted relative import beyond top-level package的原因解读)
二、命名(naming)
python包导入细节(attempted relative import beyond top-level package的原因解读)
三、不通过包导入访问一个模块

python包导入细节(attempted relative import beyond top-level package的原因解读)
四、相对导入…

python包导入细节(attempted relative import beyond top-level package的原因解读)
五、…只能用在相对导入当使用
python包导入细节(attempted relative import beyond top-level package的原因解读)
六、脚本不能包含相对导入
python包导入细节(attempted relative import beyond top-level package的原因解读)
七、解决办法
python包导入细节(attempted relative import beyond top-level package的原因解读)

感谢博主 小舔哥 :https://www.cnblogs.com/jiaxin359/p/7580375.html 的清晰讲述

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2021-03-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-25
  • 2021-12-05
  • 2021-05-31
  • 2023-03-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案