前文
??在安装grpcio的依赖的时候,竟然发现了编译失败,网上找了一大圈的,都解决不了我的问题,比如下载python-devel依赖,比如升级pip等等,最后发现原来换个方式搜就能解决问题了。 报错:
We could not diagnose your build failure. Please file an issue at http://www.github.com/grpc/grpc with `[Python install]` in the title.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/distutils/unixccompiler.py", line 196, in link
self.spawn(linker + ld_args)
File "/tmp/pip-install-ojg5tsnh/grpcio_463d3f9e791246228e226fb894ea7b10/src/python/grpcio/_spawn_patch.py", line 69, in _commandfile_spawn
_classic_spawn(self, command)
File "/usr/local/lib/python3.6/distutils/ccompiler.py", line 909, in spawn
spawn(cmd, dry_run=self.dry_run)
File "/usr/local/lib/python3.6/distutils/spawn.py", line 36, in spawn
_spawn_posix(cmd, search_path, dry_run=dry_run)
File "/usr/local/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix
% (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/pip-install-ojg5tsnh/grpcio_463d3f9e791246228e226fb894ea7b10/src/python/grpcio/commands.py", line 283, in build_extensions
build_ext.build_ext.build_extensions(self)
File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
self._build_extensions_serial()
File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
self.build_extension(ext)
File "/usr/local/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 199, in build_extension
_build_ext.build_extension(self, ext)
File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 558, in build_extension
target_lang=language)
File "/usr/local/lib/python3.6/distutils/ccompiler.py", line 717, in link_shared_object
extra_preargs, extra_postargs, build_temp, target_lang)
File "/usr/local/lib/python3.6/distutils/unixccompiler.py", line 198, in link
raise LinkError(msg)
distutils.errors.LinkError: command 'gcc' failed with exit status 1
解决
??首先要明白pip在拉依赖包的时候,默认会拉wheel包,即已经是编译好的包,那如果wheel都能拉到,自然就无须编译了。我在centos7上就默认拉到了grpcio-1.41.0-xx.whl,而在另一套alpine环境下,就出现上述的gcc compile error。 ??明白上述的问题后,实际上就是解决两个问题:1.如何拉到wheel包;2.拉不到wheel包,如何解决编译异常 ??针对第一个问题,我们可以登录grpcio的官网:https://pypi.org/project/grpcio/1.41.0/#files,查所需的linux系统的依赖包,很遗憾,没找到常用的cp36-linux包,所以官网未提供;那我们可以想办法去打造,于是我在centos7系统上根据官网tar.gz包解压后的setup.py去生成一个wheel包(命令:python setup.py bdist_wheel),发现仍旧是编译失败,于是第一条彻底失败; ??而当我搜了第二条一圈都搜不到答案时,换了一种方式搜,就搜到了,关键词:alpine grpcio gcc compile error就ok。解决方案:https://blog.csdn.net/q1026378552/article/details/111610171 。即安装两个依赖即可:
apk add build-base linux-headers
|