【问题标题】:CalledProcessError when using setup.py in Google DataFlow在 Google DataFlow 中使用 setup.py 时出现 CalledProcessError
【发布时间】:2021-01-26 16:21:50
【问题描述】:

使用 setup.py 在我的 DataFlow 工作人员上安装依赖项时出现以下错误:

CalledProcessError                        Traceback (most recent call last)
~/apache-beam-2.27.0/lib/python3.7/site-packages/apache_beam/utils/processes.py in check_output(*args, **kwargs)
     90     try:
---> 91       out = subprocess.check_output(*args, **kwargs)
     92     except OSError:

/opt/conda/lib/python3.7/subprocess.py in check_output(timeout, *popenargs, **kwargs)
    410     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 411                **kwargs).stdout
    412 

/opt/conda/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['/root/apache-beam-2.27.0/bin/python', 'setup.py', 'sdist', '--dist-dir', '/tmp/tmpcljk596r']' returned non-zero exit status 1.

我的 Setup.py 文件正是 Apache Beam 提出的,我想安装 2 个 python 模块和一个 apt-get :

CUSTOM_COMMANDS = [
    ['apt-get', 'update'],
    ['apt-get', '--assume-yes', 'install', 'poppler-utils']
]

REQUIRED_PACKAGES = ['pdf2image', 'poppler-utils']

这是一个非常痛苦的错误,因为在我看来,我使用 setup.py 选项的方式与在我的工作人员上使用 apt-get 安装依赖项的方式完全相同。

像往常一样,使用 DirectRunner 就像一个魅力 :)

我的配置:

  • Python 3.7.9 上的 Apache Beam 2.27.0
  • GCP 上的 DataFlow 笔记本
  • (在笔记本外运行 DataFlow 时遇到同样的错误)

感谢您的帮助

最好的问候

杰罗姆

【问题讨论】:

  • 你能解决吗?

标签: google-cloud-dataflow apache-beam


【解决方案1】:

我最近遇到了类似的错误...花了很长时间才修复。我不能代表所有平台或您的特定 setup.py,但我可以分享我如何在 Windows 上解决类似问题,希望这可以帮助您。

在 apache 光束源中,它使用 Python 的 subprocess 模块运行 setup 命令(您可以看到 CalledProcessError 源自该模块)。在 Windows 上,它在调用 check_output 时强制参数 shell=True,这意味着它在特定于平台的 shell 中运行命令(即通常在 windows 上为 cmd.exe)。

作为第一步,通过在 shell 中手动运行来验证您看到的引发 CalledProcessException 的命令实际上并未引发错误。在我的例子中,命令(Python setup.py study...)在手动运行时按预期工作。

然后,如果您使用的是 Windows,请确保 powershell/cmd 上的所有自动运行命令都按预期运行并且不会引发错误。如果您不在 Windows 上,我认为您应该验证您的光束代码是否使用了 shell=True,如果是,请确保您的 shell 的自动运行脚本正常工作。

在我的例子中,Beam 运行的 Python 命令在手动运行时运行良好。但是当在 shell=True 的子进程中执行时,我的 shell 中的一个损坏的自动运行命令导致 beam 从子进程接收错误代码并认为 Python 命令失败。

-泰勒

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多