快速解决[ImportError]: attempted relative import with no known parent package

最近在复现一个模型时,文件夹以及文件的相对层级之间的“引用”是正确的,出现错误:
ImportError: attempted relative import with no known parent package
[外链图片转存中…(img-mFnsFTxm-1721005647909)]
在train.py文件种需要调用,所属的文件夹的同级文件夹下的其他文件,但是:
1.from unet3d.train.train import run_training
2.from …train.train import run_training
3.在文件夹下新建一个__init__.py文件
都没有解决,有一招可以快速解决:
原始终端命令为:

python unet3d/scripts/train.py --config_filename UnetCNN/examples/tooth_me/tooth_me_config.json

更改为:

python -m unet3d.scripts.train --config_filename UnetCNN/examples/tooth_me/tooth_me_config.json

解决了!

猜你喜欢

转载自blog.csdn.net/weixin_50557558/article/details/140429393