0
点赞
收藏
分享

微信扫一扫

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


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

python中,下级模块引用上级模块:SystemError: Parent module


python中,下级模块引用上级模块:SystemError: Parent module

 运行test_count.py文件

 python中,下级模块引用上级模块:SystemError: Parent module

解决方案:在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


声明:如有侵权,请联系删除。

============================= 升职加薪 ==========================


举报

相关推荐

0 条评论