centos7安装mysqlclient踩坑记录

centos7安装mysqlclient踩坑记录

服务器环境为centos7 使用Django3.1部署一个小项目 安装mysqlclient的过程中报错

[root@guest download]# pip3.9 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.0.2.tar.gz (88 kB)
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/python3.9/bin/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bgvgypl1/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bgvgypl1/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-tla1jmlz/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/python3.9/bin/include/python3.9/mysqlclient
         cwd: /tmp/pip-install-bgvgypl1/mysqlclient/
    Complete output (31 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.9
    creating build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.9/MySQLdb
    creating build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/MySQLdb
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Dversion_info=(2,0,2,'final',0) -D__version__=2.0.2 -I/usr/include/mysql -I/usr/local/python3.9/bin/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.9/MySQLdb/_mysql.o
    MySQLdb/_mysql.c: 在函数‘_mysql_row_to_dict_cached’中:
    MySQLdb/_mysql.c:1340:5: 错误:只允许在 C99 模式下使用‘for’循环初始化声明
         for (unsigned int i=0; i<n; i++) {
         ^
    MySQLdb/_mysql.c:1340:5: 附注:使用 -std=c99 或 -std=gnu99 来编译您的代码
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/python3.9/bin/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bgvgypl1/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bgvgypl1/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-tla1jmlz/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/python3.9/bin/include/python3.9/mysqlclient Check the logs for full command output.

搜索了半天也没找到相关有效的解决方式 也怪我没有仔细的查看报错信息 只是笼统的搜索了一下
但是没有解决,看到了编译相关错误一时间好像抓住了点说明 遂查看了一下GCC的版本

[root@guest download]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright © 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。

一直用也没有注意 这GCC的版本低的可怕 遂升级试试

yum -y install centos-release-scl
yum -y install devtoolset-6-gcc devtoolset-6-gcc-c++ devtoolset-6-binutils
scl enable devtoolset-6 bash

这是临时性升级,反正我也不是很懂 一直想系统的来学学Linux 但是实在是没时间 ,所以就用到什么搜索什么 能记住的命令少的可怜
再次运行

(phone) [root@guest download]# pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.0.2.tar.gz (88 kB)
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... done
  Created wheel for mysqlclient: filename=mysqlclient-2.0.2-cp39-cp39-linux_x86_64.whl size=102051 sha256=0b63c0d94381d52378624ab963f3d03c74654c4825033ff857451f0c3b9837d6
  Stored in directory: /root/.cache/pip/wheels/2e/2e/75/15099241643a4b2bcd8cbaf6ab6353b8f8bb67192d90fdcd78
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.0.2

成功了 ,这应该也算是centos7对于Django的一个小坑了

你可能感兴趣的:(python)