Installing GDAL for python in Google Cloud Functions — error when deploying

huangapple go评论95阅读模式
英文:

Installing GDAL for python in Google Cloud Functions -- error when deploying

问题

我在Google Cloud Function中使用Python 3.9时未能成功使用GDAL。我在"requirements.txt"文件中包含了gdal:

  1. numpy
  2. pygrib
  3. requests
  4. google-cloud-storage
  5. gdal

但在部署函数时出现以下错误:

  1. 构建失败: .../setuptools/command/egg_info.py", 541, 在运行时
  2. self.add_defaults()
  3. 文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/command/egg_info.py", 578, add_defaults
  4. sdist.add_defaults(self)
  5. 文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", 228, add_defaults
  6. self._add_defaults_ext()
  7. 文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", 311, _add_defaults_ext
  8. build_ext = self.get_finalized_command('build_ext')
  9. 文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", 299, get_finalized_command
  10. cmd_obj.ensure_finalized()
  11. 文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", 107, ensure_finalized
  12. self.finalize_options()
  13. 文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 255, finalize_options
  14. gdaldir = self.get_gdal_config('prefix')
  15. 文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 194, get_gdal_config
  16. raise gdal_config_error(traceback_string + '\n' + msg)
  17. __main__.gdal_config_error: 最近的调用堆栈(最近的呼叫位于最上方):
  18. 文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 87, fetch_config
  19. p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
  20. 文件 "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", 951, __init__
  21. self._execute_child(args, executable, preexec_fn, close_fds,
  22. 文件 "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", 1821, _execute_child
  23. raise child_exception_type(errno_num, err_msg, err_filename)
  24. FileNotFoundError: [Errno 2] 没有这样的文件或目录:'gdal-config'
  25. 在处理上述异常时,发生了另一个异常:
  26. 最近的调用堆栈(最近的呼叫位于最上方):
  27. 文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 188, get_gdal_config
  28. returnfetch_config(option, gdal_config=self.gdal_config)
  29. 文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 90, fetch_config
  30. raise gdal_config_error(e)
  31. gdal_config_error: [Errno 2] 没有这样的文件或目录:'gdal-config'
  32. 无法找到gdal-config。确保您已安装GDAL原生库和开发标头。
  33. 注意:此错误源自子进程,可能与pip无关。
  34. 错误:metadata-generation-failed

回顾其他类似的帖子,例如GDAL包缺失,似乎需要在运行pip install gdal之前安装GDAL库/标头,即sudo apt-get install libgdal-dev。鉴于我无法为云函数运行apt-get,是否有人有解决方法或解决方法?

英文:

I've been unsuccessful in using GDAL in a Google Cloud Function with Python 3.9. I've included gdal in the "requirements.txt" file:

  1. numpy
  2. pygrib
  3. requests
  4. google-cloud-storage
  5. gdal

But get the following error when deploying the function:

  1. Build failed: .../setuptools/command/egg_info.py", line 541, in run
  2. self.add_defaults()
  3. File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 578, in add_defaults
  4. sdist.add_defaults(self)
  5. File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 228, in add_defaults
  6. self._add_defaults_ext()
  7. File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 311, in _add_defaults_ext
  8. build_ext = self.get_finalized_command('build_ext')
  9. File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 299, in get_finalized_command
  10. cmd_obj.ensure_finalized()
  11. File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 107, in ensure_finalized
  12. self.finalize_options()
  13. File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 255, in finalize_options
  14. gdaldir = self.get_gdal_config('prefix')
  15. File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 194, in get_gdal_config
  16. raise gdal_config_error(traceback_string + '\n' + msg)
  17. __main__.gdal_config_error: Traceback (most recent call last):
  18. File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 87, in fetch_config
  19. p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
  20. File "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", line 951, in __init__
  21. self._execute_child(args, executable, preexec_fn, close_fds,
  22. File "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", line 1821, in _execute_child
  23. raise child_exception_type(errno_num, err_msg, err_filename)
  24. FileNotFoundError: [Errno 2] No such file or directory: 'gdal-config'
  25. During handling of the above exception, another exception occurred:
  26. Traceback (most recent call last):
  27. File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 188, in get_gdal_config
  28. return fetch_config(option, gdal_config=self.gdal_config)
  29. File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 90, in fetch_config
  30. raise gdal_config_error(e)
  31. gdal_config_error: [Errno 2] No such file or directory: 'gdal-config'
  32. Could not find gdal-config. Make sure you have installed the GDAL native library and development headers.
  33. [end of output]
  34. note: This error originates from a subprocess, and is likely not a problem with pip.
  35. error: metadata-generation-failed
  36. × Encountered error while generating package metadata.
  37. ╰─> See above for output.
  38. note: This is an issue with the package mentioned above, not pip.
  39. hint: See above for details.; Error ID: c84b3231

Reviewing other similar posts, e.g. GDAL package missing, it seems that the GDAL library/headers needs to be installed, sudo apt-get install libgdal-dev, before the pip install gdal will work. Given that I can't run apt-get for a cloud function, does anyone have a fix or workaround?

答案1

得分: 2

将此内容发布为社区维基,以帮助其他社区成员解决此问题:

"GDAL Libraries is not supported by Google Cloud Function at the moment. However, you can use Cloud Run for special cases where you have full control over the container."

英文:

Posting this as a community wiki to help other community members that will encounter this issue:

GDAL Libraries is not supported by Google Cloud Function at the moment. However, you can use Cloud Run for special cases where you have full control over the container.

huangapple
  • 本文由 发表于 2023年2月6日 04:22:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355269.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定