【问题标题】:Dataflow/apache beam: manage custom module dependenciesDataflow/apache beam:管理自定义模块依赖项
【发布时间】:2019-01-16 16:56:18
【问题描述】:

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

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

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

import myothermodule

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

ImportError: No module named myothermodule

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

【问题讨论】:

    标签: python google-cloud-dataflow apache-beam


    【解决方案1】:

    当您远程运行管道时,您还需要在远程工作人员上提供任何依赖项。 为此,您应该将模块文件放入 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找到一个完整的例子。

    【讨论】:

    • 谢谢,我试过你说的,我得到了这个错误:ImportError: No module named othermodules
    • 哦,我做错了,我用init.py 命名了__init__.py,这就是我收到错误的原因,它解决了我的问题,非常感谢
    猜你喜欢
    • 2021-01-05
    • 2018-01-03
    • 2010-11-15
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 2018-08-14
    相关资源
    最近更新 更多