python3 安装mysqlclient 报错+亲测有用

报错信息

[root@iZbp1ihrdhzp9kwn7g94jiZ myproject]# pip3.11 install mysqlclient==2.1.1
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting mysqlclient==2.1.1
  Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/mysqlclient-2.1.1.tar.gz (88 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 88.1/88.1 kB 12.3 MB/s eta 0:00:00
  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) ... error
  error: subprocess-exited-with-error

  × Building wheel for mysqlclient (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [59 lines of output]
      /tmp/pip-build-env-bsxoy4ow/overlay/lib/python3.11/site-packages/setuptools/dist.py:478: SetuptoolsDeprecationWarning: Invalid dash-separated options
      !!

              ********************************************************************************
              Usage of dash-separated 'index-url' will not be supported in future
              versions. Please use the underscore name 'index_url' instead.

              By 2024-Sep-26, you need to update your project and remove deprecated calls
              or your builds will no longer be supported.

              See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.
              ********************************************************************************

      !!
        opt = self.warn_dash_deprecation(opt, section)
      mysql_config --version
      ['5.7.29']
      mysql_config --libs
      ['-L/usr/lib64/mysql', '-lmysqlclient', '-lpthread', '-lm', '-lrt', '-ldl']
      mysql_config --cflags
      ['-I/usr/include/mysql', '-m64']
      ext_options:
        library_dirs: ['/usr/lib64/mysql']
        libraries: ['mysqlclient', 'pthread', 'm', 'rt', 'dl']
        extra_compile_args: ['-std=c99', '-m64']
        extra_link_args: []
        include_dirs: ['/usr/include/mysql']
        extra_objects: []
        define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-311
      creating build/lib.linux-x86_64-cpython-311/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-311/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-311/MySQLdb
      copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-311/MySQLdb
      copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-311/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-311/MySQLdb
      copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-311/MySQLdb
      copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-311/MySQLdb
      creating build/lib.linux-x86_64-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-311/MySQLdb/constants
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.linux-x86_64-cpython-311
      creating build/temp.linux-x86_64-cpython-311/MySQLdb
      gcc -pthread -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/include/mysql -I/opt/django-cms/.venv/include -I/usr/include/python3.11 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-311/MySQLdb/_mysql.o -std=c99 -m64
      MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory
         46 | #include "Python.h"
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (mysqlclient)

环境信息

[root@iZbp1ihrdhzp9kwn7g94jiZ myproject]# uname -r
5.10.134-16.1.al8.x86_64
[root@iZbp1ihrdhzp9kwn7g94jiZ myproject]# pip3 -V
pip 24.1 from /opt/django-cms/.venv/lib64/python3.11/site-packages/pip (python 3.11)  
[root@iZbp1ihrdhzp9kwn7g94jiZ myproject]# python3 -V
Python 3.11.2

处理方式

[root@iZbp1ihrdhzp9kwn7g94jiZ myproject]# yum install python3.11-devel.x86_64
Last metadata expiration check: 3:16:08 ago on Sat 22 Jun 2024 11:35:29 AM CST.
Dependencies resolved.
=========================================================================================================================================================================
 Package                                     Architecture                      Version                                  Repository                                  Size
=========================================================================================================================================================================
Installing:
 python3.11-devel                            x86_64                            3.11.2-2.al8                             alinux3-updates                            247 k

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

Total download size: 247 k
Installed size: 929 k
Is this ok [y/N]: y
Downloading Packages:
python3.11-devel-3.11.2-2.al8.x86_64.rpm                                                                                                 1.6 MB/s | 247 kB     00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    1.6 MB/s | 247 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                 1/1
  Installing       : python3.11-devel-3.11.2-2.al8.x86_64                                                                                                            1/1
  Running scriptlet: python3.11-devel-3.11.2-2.al8.x86_64                                                                                                            1/1
  Verifying        : python3.11-devel-3.11.2-2.al8.x86_64                                                                                                            1/1

Installed:
  python3.11-devel-3.11.2-2.al8.x86_64

Complete!

再次安装mysqlclient

[root@iZbp1ihrdhzp9kwn7g94jiZ myproject]# pip3.11 install mysqlclient
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting mysqlclient
  Using cached http://mirrors.cloud.aliyuncs.com/pypi/packages/79/33/996dc0ba3f03e2399adc91a7de1f61cb14b57ebdb4cc6eca8a78723043cb/mysqlclient-2.2.4.tar.gz (90 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.4-cp311-cp311-linux_x86_64.whl size=129246 sha256=e309b42978945dee38d0659de4925f77fd6be0571d97538d1cffd3f31fe043f0
  Stored in directory: /root/.cache/pip/wheels/de/25/17/4bc7263d99c82ee5323f25d63afe7e53a42302788567bc2bd2
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.2.4

如果对您有帮助,记得关注收藏,帮助更多的人

如果对您有帮助,记得关注收藏,帮助更多的人

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据工匠大壮

请狠狠粗暴的爱我!!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值