今天使用python:3.9.7-alpine3.13镜像安装阿里云sdk的时候报错如下:
# pip3.9 install -i https://mirrors.aliyun.com/pypi/simple/ aliyun-python-sdk-polardb==1.8.11 Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ Collecting aliyun-python-sdk-polardb==1.8.11 Using cached https://mirrors.aliyun.com/pypi/packages/1a/9e/4efe749e96cc111bf0239e32eca71738ab0459783e85a541c4e32e0fca49/aliyun_python_sdk_polardb-1.8.11-py2.py3-none-any.whl (121 kB) Collecting aliyun-python-sdk-core>=2.11.5 Using cached aliyun_python_sdk_core-2.13.35-py3-none-any.whl Collecting jmespath<1.0.0,>=0.9.3 Using cached https://mirrors.aliyun.com/pypi/packages/07/cb/5f001272b6faeb23c1c9e0acc04d48eaaf5c862c17709d20e3469c6e0139/jmespath-0.10.0-py2.py3-none-any.whl (24 kB) Collecting cryptography>=2.6.0 Using cached https://mirrors.aliyun.com/pypi/packages/eb/b2/1812dfe3eefa9256e565c0c81bf2ae40698fc174e8407996d14a63faa126/cryptography-35.0.0-cp36-abi3-musllinux_1_1_x86_64.whl (3.7 MB) Collecting cffi>=1.12 Using cached https://mirrors.aliyun.com/pypi/packages/00/9e/92de7e1217ccc3d5f352ba21e52398372525765b2e0c4530e6eb2ba9282a/cffi-1.15.0.tar.gz (484 kB) Preparing metadata (setup.py) ... done Requirement already satisfied: pycparser in /usr/local/lib/python3.9/site-packages (from cffi>=1.12->cryptography>=2.6.0->aliyun-python-sdk-core>=2.11.5->aliyun-python-sdk-polardb==1.8.11) (2.20) Building wheels for collected packages: cffi Building wheel for cffi (setup.py) ... error ERROR: Command errored out with exit status 1: command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/setup.py'"'"'; __file__='"'"'/tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-vjrg5fz7 cwd: /tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/ Complete output (36 lines): running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.9 creating build/lib.linux-x86_64-3.9/cffi copying cffi/error.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/cparser.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/commontypes.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/api.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/lock.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/model.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/__init__.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/recompiler.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/verifier.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.9/cffi copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.9/cffi copying cffi/_embedding.h -> build/lib.linux-x86_64-3.9/cffi copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.9/cffi running build_ext building '_cffi_backend' extension creating build/temp.linux-x86_64-3.9 creating build/temp.linux-x86_64-3.9/c gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.9 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.9/c/_cffi_backend.o c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory 15 | #include <ffi.h> | ^~~~~~~ compilation terminated. error: command '/usr/bin/gcc' failed with exit code 1 ---------------------------------------- ERROR: Failed building wheel for cffi Running setup.py clean for cffi Failed to build cffi Installing collected packages: cffi, jmespath, cryptography, aliyun-python-sdk-core, aliyun-python-sdk-polardb Running setup.py install for cffi ... error ERROR: Command errored out with exit status 1: command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/setup.py'"'"'; __file__='"'"'/tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-eu4jjyun/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/cffi cwd: /tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/ Complete output (38 lines): running install /usr/local/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_py creating build creating build/lib.linux-x86_64-3.9 creating build/lib.linux-x86_64-3.9/cffi copying cffi/error.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/cparser.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/commontypes.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/api.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/lock.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/model.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/__init__.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/recompiler.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/verifier.py -> build/lib.linux-x86_64-3.9/cffi copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.9/cffi copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.9/cffi copying cffi/_embedding.h -> build/lib.linux-x86_64-3.9/cffi copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.9/cffi running build_ext building '_cffi_backend' extension creating build/temp.linux-x86_64-3.9 creating build/temp.linux-x86_64-3.9/c gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.9 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.9/c/_cffi_backend.o c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory 15 | #include <ffi.h> | ^~~~~~~ compilation terminated. error: command '/usr/bin/gcc' failed with exit code 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/setup.py'"'"'; __file__='"'"'/tmp/pip-install-br2hd8mo/cffi_b6a9a046f3f74280b6cf088737228244/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-eu4jjyun/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/cffi Check the logs for full command output.
主要原因是aliyun-python-sdk-polardb需要依赖cffi,cffi安装出错了。
出现这种情况,一般都是因为缺少某些系统依赖模块导致编译失败,我在网上找了下,很遗憾没有找到相关解决方法。
为了确认原因,我在centos系统使用命令pip install ciff测试一下,发现正常安装,没有报错。自己本身是在Windows系统下面开发的,所以Windows肯定是没有问题的。
这下验证了我的判断,于是开始Google各种搜索,终于让我找到的他依赖的相关模块。
安装好依赖模块以后,再安装aliyun-python-sdk-polardb一切正常。