首页 > 解决方案 > 云数据流 python3 作业未解决依赖关系

问题描述

我有一个简单的 apache 梁项目,使用 python 3 转换一些数据并写入大查询,它使用一个名为 texstat 的包,如果我在本地运行一切正常,但是当我在数据流上运行时,我收到以下错误:

NameError: name 'textstat' is not defined [while running 'generatedPtransform-441']

这是我当前的 setup.py 文件:

import setuptools

REQUIRED_PACKAGES = ['textstat==0.5.6']
PACKAGE_NAME = 'my_package'
PACKAGE_VERSION = '0.0.1'


setuptools.setup(
    name=PACKAGE_NAME,
    version=PACKAGE_VERSION,
    description='Example project',
    install_requires=REQUIRED_PACKAGES,
    packages=setuptools.find_packages(),
)

这是我的管道参数

pipeline_args = [
    '--project={}'.format('etl-example'),
    '--runner={}'.format('Dataflow'),
    '--temp_location=gs://dataflowtemporal/',
    '--setup_file=./setup.py',
]

我像这样运行它

pipeline_options = PipelineOptions(pipeline_args)
pipeline_options.view_as(StandardOptions).streaming = True
pipeline = beam.Pipeline(options=pipeline_options)
...
pipeline.run()

在运行作业之前,我还尝试在终端上运行它:

python setup.py sdist --formats=gztar

但我得到的 texstat 没有被找到的相同结果。我尝试的另一件事是没有 setup.py 并且只有参数

--requirements_file=./requirements.txt

但同样,没有找到 texstat

在这一点上,我不知道还能尝试什么。

标签: python-3.xgoogle-cloud-dataflowapache-beam

解决方案


通常这是因为该库未在您的 DoFn 中本地导入。

或者,您可以尝试https://cloud.google.com/dataflow/docs/resources/faq中提到的 --save_main_session 选项


推荐阅读