ubuntu系统中使用 pip安装mysqlclient报错解决

本文主要用于记录一下在新建的ubuntu环境下,使用pip安装mysqlclient==1.4.4的时候遇到安装失败的解决方法

失败报错如下:

(venv) amiter@ubuntu:~/PycharmProjects/bs-monitor$ pip install mysqlclient==1.4.4
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting mysqlclient==1.4.4
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz (86 kB)
    ERROR: Command errored out with exit status 1:
     command: /home/amiter/PycharmProjects/bs-monitor/venv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-dvzplz0r/mysqlclient_ee80538cee474ebb82713d4c21cfbc1e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-dvzplz0r/mysqlclient_ee80538cee474ebb82713d4c21cfbc1e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-zb2l8y3q
         cwd: /tmp/pip-install-dvzplz0r/mysqlclient_ee80538cee474ebb82713d4c21cfbc1e/
    Complete output (12 lines):
    /bin/sh: 1: mysql_config: not found
    /bin/sh: 1: mariadb_config: not found
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-dvzplz0r/mysqlclient_ee80538cee474ebb82713d4c21cfbc1e/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-dvzplz0r/mysqlclient_ee80538cee474ebb82713d4c21cfbc1e/setup_posix.py", line 61, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-dvzplz0r/mysqlclient_ee80538cee474ebb82713d4c21cfbc1e/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found
    ----------------------------------------
WARNING: Discarding https://pypi.tuna.tsinghua.edu.cn/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz#sha256=9c737cc55a5dc8dd3583a942d5a9b21be58d16f00f5fefca4e575e7d9682e98c (from https://pypi.tuna.tsinghua.edu.cn/simple/mysqlclient/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mysqlclient==1.4.4 (from versions: 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.3.8, 1.3.9, 1.3.10, 1.3.11rc1, 1.3.11, 1.3.12, 1.3.13, 1.3.14, 1.4.0rc1, 1.4.0rc2, 1.4.0rc3, 1.4.0, 1.4.1, 1.4.2, 1.4.2.post1, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 2.0.0, 2.0.1, 2.0.2, 2.0.3)
ERROR: No matching distribution found for mysqlclient==1.4.4

如上图所示,根据字面上意思看是由于找不到该版本得pypi包导致,于是使用了清华和阿里的源依旧失败,只好求助谷歌,果然看到一篇文章遇到了类似的问题ubuntu系统中使用 pip安装mysqlclient报错解决

解决方法

执行sudo apt-get install libmysqlclient-dev,安装成功之后再安装前面提到的mysqlclient包,一下就成功了。

(venv) amiter@ubuntu:~/PycharmProjects/bs-monitor$ sudo apt-get install libmysqlclient-dev      
将会同时安装下列软件:
  libmysqlclient20 mysql-common
解压缩后会消耗 10.2 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 mysql-common all 5.7.33-0ubuntu0.16.04.1 [14.8 kB]
已下载 1,684 kB,耗时 3秒 (460 kB/s)        
正在选中未选择的软件包 mysql-common。
(正在读取数据库 ... 系统当前共安装有 256280 个文件和目录。)
正准备解包 .../mysql-common_5.7.33-0ubuntu0.16.04.1_all.deb  ...
正在解包 mysql-common (5.7.33-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 libmysqlclient20:amd64。
正准备解包 .../libmysqlclient20_5.7.33-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 libmysqlclient20:amd64 (5.7.33-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 libmysqlclient-dev。
正准备解包 .../libmysqlclient-dev_5.7.33-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 libmysqlclient-dev (5.7.33-0ubuntu0.16.04.1) ...
正在处理用于 libc-bin (2.23-0ubuntu11.3) 的触发器 ...
正在处理用于 man-db (2.7.5-1) 的触发器 ...
正在设置 mysql-common (5.7.33-0ubuntu0.16.04.1) ...
update-alternatives: 使用 /etc/mysql/my.cnf.fallback 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
正在设置 libmysqlclient20:amd64 (5.7.33-0ubuntu0.16.04.1) ...
正在设置 libmysqlclient-dev (5.7.33-0ubuntu0.16.04.1) ...
正在处理用于 libc-bin (2.23-0ubuntu11.3) 的触发器 ...
(venv) amiter@ubuntu:~/PycharmProjects/bs-monitor$ pip install mysqlclient==1.4.4
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting mysqlclient==1.4.4
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz (86 kB)
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-1.4.4


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容