Ubuntu 17:无法安装mysqlclient

时间:2017-11-18 19:54:43

标签: python mysql django python-3.x pip

尝试遵循Django教程但我无法安装mysqlclient

本教程声称我可以使用以下命令执行此操作:

pip install mysqlclient

但这会产生此错误:

Collecting mysqlclient   Using cached mysqlclient-1.3.12.tar.gz
    Complete output from command python setup.py egg_info:
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-rrolctwh/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-build-rrolctwh/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-build-rrolctwh/mysqlclient/

我安装了最新的pip和virtualenv。

我希望能够安装mysqlclient,以便继续学习本教程。

4 个答案:

答案 0 :(得分:3)

您还应该安装mysql和python开发头文件和库: https://github.com/PyMySQL/mysqlclient-python#prerequisites

答案 1 :(得分:2)

我遇到了同样的问题,但按照Official mysqlclient documentation中的说明为我修好了

但只是为了澄清我是从虚拟环境运行python 3.5 安装完先决条件后,一切正常

答案 2 :(得分:1)

以下为我解决了:

<块引用>

您可能需要像这样安装 Python 3 和 MySQL 开发头文件和库:

$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu

% sudo yum install python3-devel mysql-devel # Red Hat / CentOS
<块引用>

然后就可以通过pip安装mysqlclient了:

$ pip install mysqlclient

来源:https://github.com/PyMySQL/mysqlclient#prerequisites

答案 3 :(得分:0)

我在Centos 6上也有类似的问题,mysql迁移到maria有问题,我有一些冲突,但最后我安装了:

 yum list installed |grep MariaDB
MariaDB-client.x86_64  10.2.7-1.el6     @bull                                   
MariaDB-common.x86_64  10.2.7-1.el6     @bull                                   
MariaDB-compat.x86_64  10.2.7-1.el6     @bull                                   
MariaDB-devel.x86_64   10.2.7-1.el6     @bull                                   
MariaDB-server.x86_64  10.2.7-1.el6     @bull  

问题已经解决了。