You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TFX1.2.1导入tfx.utils.dsl_utils报ModuleNotFoundError如何解决

问题原因

你当前使用的TFX 1.2.1属于1.x正式版本,旧版本TFX 0.x中存在的tfx.utils.dsl_utils模块已经被官方正式移除,对应的external_input方法也早已弃用,因此触发模块不存在的报错。

解决方案

直接调整代码适配1.x版本的API规则即可,有两种常用的兼容写法,按需选择:

方案1(最简写法,本地csv读取优先使用)

1.x版本的CsvExampleGen已经支持直接传入本地路径作为数据源,无需额外包装,修改后代码如下:

import os
from tfx.components import CsvExampleGen
base_dir = os.getcwd()
data_dir = os.path.join(os.pardir, "data")
example_gen = CsvExampleGen(input_base=os.path.join(base_dir, data_dir))
context.run(example_gen)

方案2(自定义外部数据源场景使用)

如果需要显式声明外部Artifact通道,可以用以下写法替代原external_input的逻辑:

import os
from tfx.components import CsvExampleGen
from tfx.types import Channel
from tfx.types.standard_artifacts import ExternalArtifact

base_dir = os.getcwd()
data_dir = os.path.join(os.pardir, "data")
examples = Channel(
    type=ExternalArtifact,
    artifacts=[ExternalArtifact(uri=os.path.join(base_dir, data_dir))]
)
example_gen = CsvExampleGen(input=examples)
context.run(example_gen)
注意事项
  • TFX 0.x版本和1.x版本API差异极大,不要直接照搬旧版本的教程代码,所有用法需要对应你安装的1.2.1版本调整。
  • 如果后续遇到其他参数报错,优先检查组件入参规则,常规本地数据处理场景使用方案1的写法即可覆盖绝大多数需求。

内容的提问来源于stack exchange,提问作者Phạm Tâm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 14:15:05