python - 数据流/apache 光束 : manage custom module dependencies

标签 python google-cloud-dataflow apache-beam

我有一个使用 apache beam 的 .py 管道导入另一个模块 (.py),这是我的自定义模块。 我有这样的结构:

├── mymain.py
└── myothermodule.py

我像这样在 mymain.py 中导入 myothermodule.py:

import myothermodule

当我在 DirectRuner 上本地运行时,没有问题。 但是当我使用 DataflowRunner 在数据流上运行它时,我有一个错误提示:

ImportError: No module named myothermodule

所以我想知道如果我希望在数据流上运行作业时找到这个模块,我该怎么办?

最佳答案

当您远程运行管道时,您还需要使远程工作人员也可以使用任何依赖项。 为此,您应该将模块文件放入一个 Python 包中,方法是将它放在一个包含 __init__.py 文件的目录中,并创建一个 setup.py。它看起来像这样:

├── mymain.py
├── setup.py
└── othermodules
    ├── __init__.py
    └── myothermodule.py

然后像这样导入它:

from othermodules import myothermodule

然后您可以使用命令行选项 --setup_file ./setup.py

运行管道

最小的 setup.py 文件如下所示:

import setuptools

setuptools.setup(packages=setuptools.find_packages())

整个设置记录在案here .

可以找到使用它的完整示例 here .

关于python - 数据流/apache 光束 : manage custom module dependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51763406/

相关文章:

python - matplotlib 无法在 OS X 中运行,错误为 ' TKApplication is implemented in both'

python - Apache Beam 本地 Python 依赖项

JAVA-Apache BEAM-GCP : GroupByKey works fine with Direct Runner but fails with Dataflow runner

python - 直接从 __array_interface__ 创建 NumPy 数组

远程服务器上的 Python 进程需要通过 ssh 连接到其他服务器并继续运行

python 3.3 : Convert XML to YAML

python - 从 Beam Python 示例中了解 "|"和 ">>"

java - 在 apache beam 中使用 SpannerIO 时出错

python - 如何使用 GCP Cloud SQL 作为数据流源和/或 Python 接收器?

google-cloud-dataflow - 使用 Apache Beam 从数据库中读取批量数据