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

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

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

问题

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

numpy
pygrib
requests
google-cloud-storage
gdal

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

构建失败: .../setuptools/command/egg_info.py", 行 541, 在运行时
          self.add_defaults()
        文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/command/egg_info.py", 行 578, 在add_defaults中
          sdist.add_defaults(self)
        文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", 行 228, 在add_defaults中
          self._add_defaults_ext()
        文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", 行 311, 在_add_defaults_ext中
          build_ext = self.get_finalized_command('build_ext')
        文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", 行 299, 在get_finalized_command中
          cmd_obj.ensure_finalized()
        文件 "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", 行 107, 在ensure_finalized中
          self.finalize_options()
        文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 行 255, 在finalize_options中
          gdaldir = self.get_gdal_config('prefix')
        文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 行 194, 在get_gdal_config中
          raise gdal_config_error(traceback_string + '\n' + msg)
      __main__.gdal_config_error: 最近的调用堆栈(最近的呼叫位于最上方):
        文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 行 87, 在fetch_config中
          p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
        文件 "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", 行 951, 在__init__中
          self._execute_child(args, executable, preexec_fn, close_fds,
        文件 "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", 行 1821, 在_execute_child中
          raise child_exception_type(errno_num, err_msg, err_filename)
        FileNotFoundError: [Errno 2] 没有这样的文件或目录:'gdal-config'

        在处理上述异常时,发生了另一个异常:

        最近的调用堆栈(最近的呼叫位于最上方):
        文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 行 188, 在get_gdal_config中
          returnfetch_config(option, gdal_config=self.gdal_config)
        文件 "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", 行 90, 在fetch_config中
          raise gdal_config_error(e)
        gdal_config_error: [Errno 2] 没有这样的文件或目录:'gdal-config'

        无法找到gdal-config。确保您已安装GDAL原生库和开发标头。
        
        注意:此错误源自子进程,可能与pip无关。
错误: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:

numpy
pygrib
requests
google-cloud-storage
gdal

But get the following error when deploying the function:

Build failed: .../setuptools/command/egg_info.py", line 541, in run
          self.add_defaults()
        File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 578, in add_defaults
          sdist.add_defaults(self)
        File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 228, in add_defaults
          self._add_defaults_ext()
        File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 311, in _add_defaults_ext
          build_ext = self.get_finalized_command('build_ext')
        File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 299, in get_finalized_command
          cmd_obj.ensure_finalized()
        File "/layers/google.python.pip/pip/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 107, in ensure_finalized
          self.finalize_options()
        File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 255, in finalize_options
          gdaldir = self.get_gdal_config('prefix')
        File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 194, in get_gdal_config
          raise gdal_config_error(traceback_string + '\n' + msg)
      __main__.gdal_config_error: Traceback (most recent call last):
        File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 87, in fetch_config
          p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
        File "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", line 951, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "/layers/google.python.runtime/python/lib/python3.9/subprocess.py", line 1821, in _execute_child
          raise child_exception_type(errno_num, err_msg, err_filename)
      FileNotFoundError: [Errno 2] No such file or directory: 'gdal-config'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 188, in get_gdal_config
          return fetch_config(option, gdal_config=self.gdal_config)
        File "/tmp/pip-install-d9gag00y/gdal_e01a421a21914f03a3c89fd3914501b0/setup.py", line 90, in fetch_config
          raise gdal_config_error(e)
      gdal_config_error: [Errno 2] No such file or directory: 'gdal-config'
      
      Could not find gdal-config. Make sure you have installed the GDAL native library and development headers.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
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:

确定