CentOS下安装MySQL时报错

2 篇文章 0 订阅
1 篇文章 0 订阅

背景

在CentOS中创建django项目后,需要安装虚拟环境,结果安装到mysqlclient==1.3.12时报错,就终止安装了。然后在网上百度了一大堆,才找到可行的解决的办法。

1、报错信息如下

Collecting mysqlclient==1.3.12 (from -r requirements.txt (line 41))
  Using cached https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz
    Complete output from command python setup.py egg_info:
    /bin/sh: mysql_config: 未找到命令
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-s2vvlk8n/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-s2vvlk8n/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-install-s2vvlk8n/mysqlclient/setup_posix.py", line 26, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-s2vvlk8n/mysqlclient/

主要的错误原因是:OSError: mysql_config not found。 mysql_config 找不到,所以导致mysqlclient安装不上。

2、 解决办法

在安装mysqlclient时,先执行如下语句

(envir_vir) [root@localhost /] # yum install mysql-devel gcc gcc-devel python-devel

如果看到有如下信息,就是执行成功了:

Running transaction
  正在安装    : python-devel-2.7.5-76.el7.x86_64                            1/2 
  正在安装    : mysql-community-devel-5.7.24-1.el7.x86_64                   2/2 
  验证中      : mysql-community-devel-5.7.24-1.el7.x86_64                   1/2 
  验证中      : python-devel-2.7.5-76.el7.x86_64                            2/2 

已安装:
  mysql-community-devel.x86_64 0:5.7.24-1.el7                                   
  python-devel.x86_64 0:2.7.5-76.el7                                            

完毕!

3、重新安装mysqlclient

在上一步安装成功后,就可以继续重新安装mysqlclient==1.3.12了

(envir_vir) [root@localhost /]# pip install mysqlclient==1.3.12
Collecting mysqlclient==1.3.12
  Using cached https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... done
  Stored in directory: /root/.cache/pip/wheels/50/c7/31/81a516762c8e9324f2b1fdffc1e84b9f07224fe3707956f6e1
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.12
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值