MySQL是常用的开源数据库,Python环境下django框架连接MySQL数据库用的是mysqlclient库,今天在用pip安装mysqlclient库时报错,特记录一下,避免后续继续踩坑。

环境说明:

操作系统:CentOS Linux 7.2
Python版本:Python 3.9.13
pip版本:pip 22.1.2

报错信息:

执行 pip3 install mysqlclient==2.1.1 报错
报错信息如下:

Using cached http://mirrors.aliyun.com/pypi/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/mysqlclient-2.1.1.tar.gz (88 kB)
  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-i1nt_asj/mysqlclient_1b92535d58cd440b8797686ac8bc9882/setup.py", line 15, in <module>
          metadata, options = get_config()
        File "/tmp/pip-install-i1nt_asj/mysqlclient_1b92535d58cd440b8797686ac8bc9882/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/tmp/pip-install-i1nt_asj/mysqlclient_1b92535d58cd440b8797686ac8bc9882/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
通过whereis mysql_config命令查看mysql_config
发现mysql_confg没有
执行yum install mysql-devel 安装mysql-devel
执行whereis mysql_config命令查看mysql_config这时mysql_config有了

mysql_config: /usr/bin/mysql_config /usr/share/man/man1/mysql_config.1.gz

再次执行pip安装命令安装成功!

pip3 install mysqlclient==2.1.1
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting mysqlclient==2.1.1
  Using cached http://mirrors.aliyun.com/pypi/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/mysqlclient-2.1.1.tar.gz (88 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.1
                    MySQL是常用的开源数据库,Python环境下django框架连接MySQL数据库用的是mysqlclient库,今天在用pip安装mysqlclient库时报错,特记录一下,避免后续继续踩坑。
				
安装myclient时老是 pip安装错:is not a supported wheel on this platform 其实问题很简单,就是myclient版本出现了错误, 如果使用下面的代码出现错误,  &gt;&gt;&gt; import pip &gt;&gt;&gt; print(pip.pep425tags.get_supported()) 可以试一下下面的代码 生成了如下结构 [code=html] <figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /opt</span><br><span class="line">git <span class="built_in">clone</span> https://github.com/titansec/OpenWAF.git</span><br><span class="line">mv /opt/OpenWAF/lib/openresty/ngx_openwaf.conf /etc</span><br><span class="line">mv /opt/OpenWAF/lib/openresty/configure /opt/openresty-1.19.3.1</span><br><span class="line">cp -RP /opt/OpenWAF/lib/openresty/* /opt/openresty-1.19.9.1/bundle/</span><br><span class="line"><span class="built_in">cd</span> /opt/OpenWAF/</span><br><span class="line">make clean</spa [/code] 网络信息安全之纵深防御 守门猿阿七: waf和rasp一起用,基本就都能照顾到南北向和东西向的流量。长亭的waf刚刚开源,悬镜的rasp也有免费版本,很低成本就能搭起来整个体系。 机器学习实现恶意URL检测实战一 xiejava1018: 目前的训练数据是有局限性的,你可以多拿点正常的数据进行训练。 机器学习实现恶意URL检测实战一 liaotinghao: 博主,我能成功运行这个模型,但是结果好像有点问题,我就算输入百度的url结果都是bad,可以联系上您问点问题吗 修改成清华镜像源解决Anaconda报The channel is not accessible源通道不可用问题 有用,太棒了!亲测有用。