简体   繁体   中英

Ubuntu 17: Can't install mysqlclient

Trying to follow a Django tutorial but I cannot install mysqlclient .

The tutorial claims that I can do so with the following command:

pip install mysqlclient

but this generates this error:

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/

I have the most up-to-date pip and virtualenv installed.

I would like to be able to install mysqlclient so that I may continue with the tutorial.

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

I was facing the same problems, but following the instructions in the Official mysqlclient documentation fixed it for me

but just to clarify I was running python 3.5 from a virtual environment and after installing the prerequisites, it all worked fine

The following solved it for me :

You may need to install the Python 3 and MySQL development headers and libraries like so:

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

% sudo yum install python3-devel mysql-devel # Red Hat / CentOS

Then you can install mysqlclient via pip now:

$ pip install mysqlclient

Source : https://github.com/PyMySQL/mysqlclient#prerequisites

I had also similar issue on Centos 6, where there was a problem with mysql migration to maria, I had some conflicts, but finally I installed:

 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  

And the issue was resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM