google-cloud-platform - fbprophet 未能在谷歌云功能中构建轮子
问题描述
我希望在Python 3.7 环境中的云函数上使用 Fbprophet ,但它无法构建并给我以下错误。
Build failed: `pip_download_wheels` had stderr output:
ERROR: Command errored out with exit status 1:
command: /opt/python3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-wheel-srnqu7b5/fbprophet/setup.py'"'"'; __file__='"'"'/tmp/pip-wheel-srnqu7b5/fbprophet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-3_5khs54
cwd: /tmp/pip-wheel-srnqu7b5/fbprophet/
Complete output (40 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/fbprophet
creating build/lib/fbprophet/stan_model
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-wheel-srnqu7b5/fbprophet/setup.py", line 148, in <module>
"""
File "/opt/python3.7/lib/python3.7/site-packages/setuptools/__init__.py", line 140, in setup
return distutils.core.setup(**attrs)
File "/opt/python3.7/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/opt/python3.7/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/opt/python3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/opt/python3.7/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 202, in run
self.run_command('build')
File "/opt/python3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/opt/python3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/opt/python3.7/lib/python3.7/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/opt/python3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/opt/python3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/tmp/pip-wheel-srnqu7b5/fbprophet/setup.py", line 48, in run
build_models(target_dir)
File "/tmp/pip-wheel-srnqu7b5/fbprophet/setup.py", line 36, in build_models
from fbprophet.models import StanBackendEnum
File "/tmp/pip-wheel-srnqu7b5/fbprophet/fbprophet/__init__.py", line 8, in <module>
from fbprophet.forecaster import Prophet
File "/tmp/pip-wheel-srnqu7b5/fbprophet/fbprophet/forecaster.py", line 14, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
----------------------------------------
ERROR: Failed building wheel for fbprophet
ERROR: Failed to build one or more wheels
error: `pip_download_wheels` returned code: 1; Error ID: 618AA8E7
这是我的requirements.txt
文件的样子:
cython
pystan
numpy
pandas==1.0.3
google-cloud-storage==1.29.0
fbprophet
geopy==1.22.0
google-cloud-bigquery==1.25.0
在 jupyter notebook 上的 Python 3.7 虚拟环境中,一切都在本地运行良好。将不胜感激任何帮助,因为我花了几乎一整天的时间试图解决这个问题,但无济于事。
解决方案
我有类似的问题。我的目标是部署一个函数,当传递一些输入时,将其输入到 Prophet 模型中,以便在将预测传递到我系统的另一部分之前进行预测。
据我所知,有几件事使这变得复杂。
首先,@mgoya 在上面的评论中提到了构建依赖项的问题。这在安装 Prophet 和安装 Pystan(Prophet 的依赖项)时都会出现。在我的cloudbuild.yaml
我试图通过按顺序安装依赖项来规避这个问题,如下所示:
steps:
- name: 'docker.io/library/python:3.9'
entrypoint: /bin/sh
# Run pip install and pytest in the same build step
# (pip packages won't be preserved in future steps!)
args: [-c, 'pip uninstall pystan; pip install convertdate==2.1.2 lunarcalendar==0.0.9 holidays==0.10.3 pgen tqdm cython pandas numpy setuptools; pip install pystan==2.19.1.1; pip install -r requirements.txt']
timeout: 1200s
这首先卸载 Pystan(如果本地存在的话),然后安装 Pystan 的构建依赖项(Prophet 的构建依赖项),然后安装 Prophet(包含在 my 中requirements.txt
)。
注意分号。我在使用双&符号时遇到了问题(即pip install ... && pip install ... etc.
。我相信这可能是由于已安装的软件包进入本地文件系统并可供以下命令使用的方式。通过运行它们&&
似乎尝试一次运行它们,这不会让安装的早期部分有时间传播并被后面的步骤发现。使用分号似乎对此有所帮助,但充其量只是轶事证据。
您也可以尝试使用,python -m pip install ...
而不是pip install
虽然我对 Python 不够熟悉,但无法告诉您我脑海中的区别。
其次,安装 Pystan 有内存要求。我在某处读到 Pystan 需要 4GB 内存才能安装。cloudbuild的默认值machine_type
没有那么多。您可以尝试通过更改其类型来增加机器的大小。
最后,还有为函数执行分配的资源。同样,我在某处读到 Prophet / Pystan 需要 2GB 内存才能运行其中一个模型。因此,如果您的云功能没有此功能,则在尝试执行时可能会遇到内存问题。根据我目前的经验,内存问题在 Google Cloud中并不是那么透明。
--
我目前的想法(也许我会向其他阅读这篇文章的人推荐)是考虑到依赖关系的重要性,Cloud Functions 是否是正确的工具。考虑到它们的构建和运行时资源要求,Pystan 和 Prophet 是相当特殊的依赖关系。
我选择做的是(在本地)构建一个包含这些依赖项的容器,并将其推送到 Google 的 Container Registry。从这里开始,我的计划是使用该容器作为 Cloud Run 应用程序的基础映像,这样部署起来要容易得多。这有明显的缺点,但如果我的基本图像不经常更改(它会),我认为这种方法会很好。不幸的是,Cloud Functions 不支持这种模型(“自带容器”)——它的设计是在你只带代码的地方。
推荐阅读
- java - 如何对 AWS Presigned URL 执行 HEAD 操作?
- python - Django 自定义 order_by 算法
- java - 使用休息模板的多张贴请求
- database - 将在线 shopify 商店链接到外部数据库
- html - Bootstrap 导航栏没有间距
- javascript - 不和谐机器人中的错误消息?(discord.js)
- java - JOOQ - 有条件加入或不退出
- javascript - 指数移动平均线与币安不匹配
- cplex - CPLEX:如何为元组键构造 excel 数据
- javascript - 当应用程序再次恢复时,FileSystem.uploadAsync 的 promise 会发生什么?