麻烦在ubuntu18.04上安装mysqlclient

时间:2019-11-27 18:52:20

标签: python django linux

我正在尝试在ubuntu 18.04上为Django项目安装mysqlclient,但是在安装mysql时遇到问题。这是来自终端的信息:

pip install mysqlclient

Collecting mysqlclient

      ----------------------------------------
      Failed building wheel for mysqlclient
      Running setup.py clean for mysqlclient
2.7/MySQLdb/constants
        running build_ext
        building 'MySQLdb._mysql' extension
        creating build/temp.linux-x86_64-2.7
        creating build/temp.linux-x86_64-2.7/MySQLdb
        x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -
    Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-PPrPZj/python2.7-2.7.15=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/opt/lampp/include/mysql -I/opt/lampp/include/mysql/mysql -I/usr/include/python2.7 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-2.7/MySQLdb/_mysql.o
        MySQLdb/_mysql.c:29:10: fatal error: mysql.h: No such file or directory`enter code here`
         #include "mysql.h"
                  ^~~~~~~~~
        compilation terminated.
        error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

1 个答案:

答案 0 :(得分:-1)

您必须安装MySQL标头。

sudo apt install libmysqlclient-dev

(并且停止使用Python 2.7,它在一个月内就不再受支持了)