centos7安装python的mysqlclient库,解决依赖的问题

安装mysqlclient时报错

[root@ ~]# pip install mysqlclient
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting mysqlclient
  Downloading https://mirrors.aliyun.com/pypi/packages/61/68/810093cb579daae426794bbd9d88aa830fae296e85172d18cb0f0e5dd4bc/mysqlclient-2.2.7.tar.gz (91 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 91.4/91.4 kB 9.3 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [26 lines of output]
      Trying pkg-config --exists mysqlclient
      Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
      Trying pkg-config --exists mariadb
      Command 'pkg-config --exists mariadb' returned non-zero exit status 1.
      Trying pkg-config --exists libmariadb
      Command 'pkg-config --exists libmariadb' returned non-zero exit status 1.
      Trying pkg-config --exists perconaserverclient
      Command 'pkg-config --exists perconaserverclient' returned non-zero exit status 1.
      Traceback (most recent call last):
        File "/www/wwwroot/pythonEnv/pyETL/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/www/wwwroot/pythonEnv/pyETL/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/www/wwwroot/pythonEnv/pyETL/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/tmp/pip-build-env-xu6letsb/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "/tmp/pip-build-env-xu6letsb/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-xu6letsb/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 320, in run_setup
          exec(code, locals())
        File "<string>", line 156, in <module>
        File "<string>", line 49, in get_config_posix
        File "<string>", line 28, in find_package_name
      Exception: Can not find valid pkg-config name.
      Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

这是因为没有找到mysql的开发文件,现在需要安装 mysql-devel

[root ~]# yum install mysql-devel
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                | 3.6 kB  00:00:00     
epel                                                                                                                | 4.3 kB  00:00:00     
extras                                                                                                              | 2.9 kB  00:00:00     
updates                                                                                                             | 2.9 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.68-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be installed
Removing mariadb-libs.x86_64 1:5.5.68-1.el7 - u due to obsoletes from installed mysql-community-libs-5.7.40-1.el7.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Finished Dependency Resolution
Error: Package: 1:mariadb-devel-5.5.68-1.el7.x86_64 (base)
           Requires: libmysqlclient.so.18()(64bit)
Error: Package: 1:mariadb-devel-5.5.68-1.el7.x86_64 (base)
           Requires: mariadb-libs(x86-64) = 1:5.5.68-1.el7
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
           Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
           Requires: libmysqlclient.so.18()(64bit)
 You could try using --skip-broken to work around the problem
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
systemd-libs-219-78.el7_9.9.x86_64 is a duplicate with systemd-libs-219-78.el7_9.7.i686

mysql-devel安装报错,原因是需要 libmysqlclient.so.18 库,而你的系统上可能已经安装了其他版本的 MySQL(如 mysql-community-libs),因此出现了版本冲突。
解决办法:
查出来mariadb之后,全部删除

[root~]# rpm -qa | grep mariadb #查出后全部删除

# 下载适配的资源
[root@ tools]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
--2025-01-14 10:27:00--  https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 104.68.105.36, 2600:1417:7800:282::2e31, 2600:1417:7800:280::2e31
Connecting to dev.mysql.com (dev.mysql.com)|104.68.105.36|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm [following]
--2025-01-14 10:27:01--  https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.203.223.154, 2600:1417:7800:28c::1d68, 2600:1417:7800:280::1d68
Connecting to repo.mysql.com (repo.mysql.com)|23.203.223.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-11.noarch.rpm’

100%[=================================================================================================>] 25,680       166KB/s   in 0.2s   

2025-01-14 10:27:02 (166 KB/s) - ‘mysql57-community-release-el7-11.noarch.rpm’ saved [25680/25680]

# 安装资源
[root@ tools]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
warning: mysql57-community-release-el7-11.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-11 ################################# [100%]

改为安装mysql-community-devel,安装时遇错

(pyETL) [root@  tools]# yum install mysql-community-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
mysql-connectors-community                                                                                          | 2.6 kB  00:00:00     
mysql-tools-community                                                                                               | 2.6 kB  00:00:00     
mysql57-community                                                                                                   | 2.6 kB  00:00:00     
(1/3): mysql-tools-community/x86_64/primary_db                                                                      | 102 kB  00:00:00     
(2/3): mysql-connectors-community/x86_64/primary_db                                                                 | 121 kB  00:00:00     
(3/3): mysql57-community/x86_64/primary_db                                                                          | 361 kB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.7.44-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================
 Package                                 Arch                     Version                        Repository                           Size
===========================================================================================================================================
Installing:
 mysql-community-devel                   x86_64                   5.7.44-1.el7                   mysql57-community                   4.7 M

Transaction Summary
===========================================================================================================================================
Install  1 Package

Total download size: 4.7 M
Installed size: 28 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-devel-5.7.44-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Public key for mysql-community-devel-5.7.44-1.el7.x86_64.rpm is not installed
mysql-community-devel-5.7.44-1.el7.x86_64.rpm                                                                       | 4.7 MB  00:00:01     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-11.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y


Public key for mysql-community-devel-5.7.44-1.el7.x86_64.rpm is not installed


 Failing package is: mysql-community-devel-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

删除mysql的公钥并重新导入

[root@ tools]# rm -f /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[root@ tools]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

再次安装

[root@ tools]# yum install mysql-community-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.7.44-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================
 Package                                 Arch                     Version                        Repository                           Size
===========================================================================================================================================
Installing:
 mysql-community-devel                   x86_64                   5.7.44-1.el7                   mysql57-community                   4.7 M

Transaction Summary
===========================================================================================================================================
Install  1 Package

Total size: 4.7 M
Installed size: 28 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
systemd-libs-219-78.el7_9.9.x86_64 is a duplicate with systemd-libs-219-78.el7_9.7.i686
  Installing : mysql-community-devel-5.7.44-1.el7.x86_64                                                                               1/1 
  Verifying  : mysql-community-devel-5.7.44-1.el7.x86_64                                                                               1/1 

Installed:
  mysql-community-devel.x86_64 0:5.7.44-1.el7                                                                                              

Complete!

获取编译标志,并写入环境变量

[root@ tools]# mysql_config --cflags
-I/usr/include/mysql -m64 
[root@ tools]# source ~/.bashrc
# 在末尾添加
# mysql libso文件
export CFLAGS="-I/usr/include/mysql"
export LDFLAGS="-L/usr/lib64/mysql"
export MYSQL_CONFIG=/usr/bin/mysql_config
[root@ tools]# source ~/.bashrc

重新安装mysqlclient

[root@ tools]# pip install mysqlclient
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting mysqlclient
  Using cached https://mirrors.aliyun.com/pypi/packages/61/68/810093cb579daae426794bbd9d88aa830fae296e85172d18cb0f0e5dd4bc/mysqlclient-2.2.7.tar.gz (91 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (pyproject.toml) ... done
  Created wheel for mysqlclient: filename=mysqlclient-2.2.7-cp39-cp39-linux_x86_64.whl size=80533 sha256=e5e04ba5fbceb3757b411643b0b7b1cdeaeb57a18f38fd79fd8badac6a2f99b2
  Stored in directory: /root/.cache/pip/wheels/40/9f/6f/65f90036c33f23cc58e42821267471d64d82d4d1fe18cad201
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.2.7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值