当在下级中引用上级时,使用相对导包会出错,SystemError: Parent module '' not loaded, cannot perform relative import

python中,下级模块引用上级模块:SystemError: Parent module '' not loaded, cannot perform relative import

 

python中,下级模块引用上级模块:SystemError: Parent module '' not loaded, cannot perform relative import

 运行test_count.py文件

 python中,下级模块引用上级模块:SystemError: Parent module '' not loaded, cannot perform relative import

解决方案:在test_count.py文件中加入如下代码,将上上级路径加入到环境变量中

import os
import sys
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, path)

 path的值打印出来是F:\uncleyong,此时直接import count就不会出问题了

python中,下级模块引用上级模块:SystemError: Parent module '' not loaded, cannot perform relative import

 

相关文章:

  • 2022-12-23
  • 2023-01-04
  • 2022-12-23
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2021-08-19
  • 2021-04-05
  • 2022-01-05
  • 2021-12-23
  • 2021-09-06
相关资源
相似解决方案