简体   繁体   English

Ubuntu 17:无法安装 mysqlclient

[英]Ubuntu 17: Can't install mysqlclient

Trying to follow a Django tutorial but I cannot install mysqlclient .试图遵循 Django 教程,但我无法安装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.我安装了最新的 pip 和 virtualenv。

I would like to be able to install mysqlclient so that I may continue with the tutorial.我希望能够安装mysqlclient以便我可以继续本教程。

您还应该安装 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我遇到了同样的问题,但按照官方 mysqlclient 文档中的说明为我修复了它

but just to clarify I was running python 3.5 from a virtual environment and after installing the prerequisites, it all worked fine但只是为了澄清我是在虚拟环境中运行 python 3.5 并且在安装先决条件后,一切正常

The following solved it for me :以下为我解决了这个问题:

You may need to install the Python 3 and MySQL development headers and libraries like so:您可能需要像这样安装 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

Then you can install mysqlclient via pip now:然后你现在可以通过pip安装mysqlclient:

$ pip install mysqlclient

Source : https://github.com/PyMySQL/mysqlclient#prerequisites来源: 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:我在 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  

And the issue was resolved.并且问题得到了解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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