Amazon Linux 2上安装postgresql15-contrib因Python共享库依赖失败
问题:Amazon Linux 2安装PostgreSQL 15 contrib包时Python依赖失败
我在AWS EC2的Amazon Linux 2系统上安装PostgreSQL 15服务器及contrib扩展库,执行步骤:
sudo rpm --import https://yum.postgresql.org/RPM-GPG-KEY-PGDG-15 sudo yum update -y sudo yum install -y postgresql15-server postgresql15-contrib
PostgreSQL服务器安装正常,但contrib包因Python依赖安装失败,单独安装postgresql15-server可正常运行。
错误信息
执行sudo yum install -y postgresql15-contrib时的错误:
[ec2-user@ip-172-31-51-199 ~]$ sudo yum install -y postgresql15-contrib Loaded plugins: dkms-build-requires, extras_suggestions, langpacks, priorities, update-motd 225 packages excluded due to repository priority protections Resolving Dependencies --> Running transaction check ---> Package postgresql15-contrib.x86_64 0:15.2-1PGDG.rhel7 will be installed --> Processing Dependency: libxslt.so.1(LIBXML2_1.0.22)(64bit) for package: postgresql15-contrib-15.2-1PGDG.rhel7.x86_64 --> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: postgresql15-contrib-15.2-1PGDG.rhel7.x86_64 --> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: postgresql15-contrib-15.2-1PGDG.rhel7.x86_64 --> Processing Dependency: libxslt.so.1()(64bit) for package: postgresql15-contrib-15.2-1PGDG.rhel7.x86_64 --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: postgresql15-contrib-15.2-1PGDG.rhel7.x86_64 --> Running transaction check ---> Package libxslt.x86_64 0:1.1.28-6.amzn2 will be installed ---> Package postgresql15-contrib.x86_64 0:15.2-1PGDG.rhel7.x86_64 --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: postgresql15-contrib-15.2-1PGDG.rhel7.x86_64 --> Finished Dependency Resolution Error: Package: postgresql15-contrib-15.2-1PGDG.rhel7.x86_64 (pgdg15) Requires: libpython3.6m.so.1.0()(64bit) Available: python3-libs-3.6.2-3.amzn2.0.2.x86_64 (amzn2extra-python3) libpython3.6m.so.1.0()(64bit) Available: python3-libs-3.6.2-3.amzn2.0.3.x86_64 (amzn2extra-python3) libpython3.6m.so.1.0()(64bit) Installed: python3-libs-3.7.16-1.amzn2.0.2.x86_64 (@amzn2-core) ~libpython3.7m.so.1.0()(64bit) Available: python3-libs-3.7.0-0.12.b2.amzn2.0.2.x86_64 (amzn2-core) ~libpython3.7m.so.1.0()(64bit) Available: python3-libs-3.7.0-0.16.b3.amzn2.0.1.x86_64 (amzn2-core) ~libpython3.7m.so.1.0()(64bit) Available: python3-libs-3.7.0-0.20.rc1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.0-0.20.rc1.amzn2.0.2.i686 (amzn2-core) Not found Available: python3-libs-3.7.1-9.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.2-4.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.3-1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.3-1.amzn2.0.2.i686 (amzn2-core) Not found Available: python3-libs-3.7.4-1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.4-1.amzn2.0.2.i686 (amzn2-core) Not found Available: python3-libs-3.7.4-1.amzn2.0.3.i686 (amzn2-core) Not found Available: python3-libs-3.7.4-1.amzn2.0.4.i686 (amzn2-core) Not found Available: python3-libs-3.7.6-1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.8-1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.9-1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.9-1.amzn2.0.2.i686 (amzn2-core) Not found Available: python3-libs-3.7.9-1.amzn2.0.3.i686 (amzn2-core) Not found Available: python3-libs-3.7.10-1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.15-1.amzn2.0.1.i686 (amzn2-core) Not found Available: python3-libs-3.7.15-1.amzn2.0.2.i686 (amzn2-core) Not found Available: python3-libs-3.7.16-1.amzn2.0.1.i686 (amzn2-core) Not found You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [ec2-user@ip-172-31-51-199 ~]$
当前环境信息
- 已安装Python版本:
[ec2-user@ip-172-31-51-199 ~]$ python3 -V Python 3.7.16 [ec2-user@ip-172-31-51-199 ~]$
- Python共享库查找结果:
[ec2-user@ip-172-31-51-199 ~]$ sudo locate libpython /home/ec2-user/timp/Python-3.6.12/libpython3.6m.a /home/ec2-user/timp/Python-3.6.12/Tools/gdb/libpython.py /usr/lib64/libpython2.7.so /usr/lib64/libpython2.7.so.1.0 /usr/lib64/libpython3.7m.so.1.0 /usr/lib64/libpython3.8.so.1.0 /usr/lib64/libpython3.so /usr/lib64/python2.7/config/libpython2.7.so /usr/local/lib/libpython3.6m.a /usr/local/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6m.a /usr/share/systemtap/tapset/libpython2.7-64.stp [ec2-user@ip-172-31-51-199 ~]$
已尝试的操作
- 单独安装
postgresql15-server正常 - 尝试安装Python 3.6版本(通过包管理及源码编译安装),问题仍未解决
解决方案
问题根源
- PGDG仓库提供的
postgresql15-contrib包基于RHEL7编译,依赖Python 3.6的动态共享库libpython3.6m.so.1.0 - Amazon Linux 2默认
amzn2-core仓库提供Python 3.7版本,Python 3.6的库存在于amzn2extra-python3仓库,但该仓库优先级低于amzn2-core,Yum无法自动选择安装 - 源码编译的Python 3.6仅生成静态库(
.a文件),Yum需要动态共享库(.so文件),因此无法被识别
具体解决步骤
方法1:启用amzn2extra-python3仓库并安装Python 3.6依赖
# 启用Python 3.6的官方扩展仓库 sudo amazon-linux-extras enable python3.6 # 清理Yum缓存,确保仓库配置生效 sudo yum clean all # 明确指定安装Python 3.6的库及contrib包 sudo yum install -y python3-libs-3.6.2 postgresql15-contrib
方法2:重新编译Python 3.6生成动态共享库
若坚持使用源码编译的Python 3.6,需添加编译参数生成动态库:
# 进入Python 3.6源码目录 cd /home/ec2-user/timp/Python-3.6.12 # 重新配置编译参数,启用动态共享库生成 ./configure --enable-shared --prefix=/usr/local # 清理之前的编译文件,重新编译安装 make clean make sudo make install # 更新系统库缓存,让系统识别新的动态库 sudo ldconfig
方法3:使用Amazon Linux 2官方PostgreSQL包
若可接受非最新版本的PostgreSQL,直接使用系统自带仓库安装:
# 移除PGDG仓库配置 sudo rm -f /etc/yum.repos.d/pgdg-15.repo # 安装官方的PostgreSQL及contrib包 sudo yum install -y postgresql-server postgresql-contrib
内容的提问来源于stack exchange,提问作者maxTrialfire
相关产品推荐
相关产品推荐

