解决centos7安装mysqlclient的错误

2022/4/30 19:15:48

本文主要是介绍解决centos7安装mysqlclient的错误,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

基本版本信息
  • centos7.9
  • python3.8.6
  • django3.1.5

安装mysqlclient需要如下错误:

[root@145-63 bseip-backend-admin]# pip3 install mysqlclient                                                                                                                           
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/                                                                                                                            
Collecting mysqlclient                                                                                                                                                                
  Downloading http://mirrors.aliyun.com/pypi/packages/de/79/d02be3cb942afda6c99ca207858847572e38146eb73a7c4bfe3bdf154626/mysqlclient-2.1.0.tar.gz (87 kB)                             
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.6/87.6 KB 193.8 kB/s eta 0:00:00                                                                                                     
  Preparing metadata (setup.py) ... error                                                                                                                                             
  error: subprocess-exited-with-error                                                                                                                                                 
                                                                                                                                                                                      
  × python setup.py egg_info did not run successfully.                                                                                                                                
  │ exit code: 1                                                                                                                                                                      
  ╰─> [16 lines of output]                                                                                                                                                            
      /bin/sh: mysql_config: command not found                                                                                                                                        
      /bin/sh: mariadb_config: command not found                                                                                                                                      
      /bin/sh: mysql_config: command not found                                                                                                                                        
      Traceback (most recent call last):                                                                                                                                              
        File "<string>", line 2, in <module>                                                                                                                                          
        File "<pip-setuptools-caller>", line 34, in <module>                                                                                                                          
        File "/tmp/pip-install-5y7mr_zh/mysqlclient_179014460dd4451e9991237ca7ebcb86/setup.py", line 15, in <module>                                                                  
          metadata, options = get_config()                                                                                                                                            
        File "/tmp/pip-install-5y7mr_zh/mysqlclient_179014460dd4451e9991237ca7ebcb86/setup_posix.py", line 70, in get_config                                                          
          libs = mysql_config("libs")                                                                                                                                                 
        File "/tmp/pip-install-5y7mr_zh/mysqlclient_179014460dd4451e9991237ca7ebcb86/setup_posix.py", line 31, in mysql_config                                                        
          raise OSError("{} not found".format(_mysql_config_path))                                                                                                                    
      OSError: mysql_config not found                                                                                                                                                 
      mysql_config --version                                                                                                                                                          
      mariadb_config --version                                                                                                                                                        
      mysql_config --libs                                                                                                                                                             
      [end of output]                                                                                                                                                                 
                                                                                                                                                                                      
  note: This error originates from a subprocess, and is likely not a problem with pip.                                                                                                
error: metadata-generation-failed                                                                                                                                                     
                                                                                                                                                                                      
× Encountered error while generating package metadata.                                                                                                                                
╰─> See above for output.                                                                                                                                                             
                                                                                                                                                                                      
note: This is an issue with the package mentioned above, not pip.                                                                                                                     
hint: See above for details.                                      

  

错误信息可以看出来, mysql_config这个依赖包出现了问题。
解决问题:
添加软连接

ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config

添加软连接以后还是不行的话呢,再做如下操作:

# 先安装mysql-devel,后安装mysqlclient
yum install mysql-devel
pip3 install mysqlclient

  

完美解决问题

[root@145-63 bseip-backend-admin]# pip3 install mysqlclient                                                                                                                           
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/                                                                                                                            
Collecting mysqlclient                                                                                                                                                                
  Using cached http://mirrors.aliyun.com/pypi/packages/de/79/d02be3cb942afda6c99ca207858847572e38146eb73a7c4bfe3bdf154626/mysqlclient-2.1.0.tar.gz (87 kB)                            
  Preparing metadata (setup.py) ... done                                                                                                                                              
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.                                                                                              
Installing collected packages: mysqlclient                                                                                                                                            
  Running setup.py install for mysqlclient ... done                                                                                                                                   
Successfully installed mysqlclient-2.1.0 

  



这篇关于解决centos7安装mysqlclient的错误的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程