1.将source path 加入到sys目录里文章来源:https://www.toymoban.com/news/detail-805451.html
# your project dir
>>> PROJ_DIR = 'xxxx'
# append to sys.path
>>> sys.path.append(os.path.join(PROJ_DIR, 'nmt'))
2.将相对导入改成直接导入,去掉 “."文章来源地址https://www.toymoban.com/news/detail-805451.html
##修改前
def train(self, training_config=None, **kwargs):
from .train_sts_task import train_sts ##
train_sts(self._model, training_config)
##修改后
def train(self, training_config=None, **kwargs):
from train_sts_task import train_sts ##去掉"."
train_sts(self._model, training_config)
到了这里,关于ImportError: attempted relative import with no known parent package的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!