首页 > 解决方案 > 麻烦在ubuntu18.04上安装mysqlclient

问题描述

我正在尝试在 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

标签: pythondjangolinux

解决方案


您必须安装 MySQL 标头。

sudo apt install libmysqlclient-dev

(停止使用 Python 2.7,一个月后就不再支持了)


推荐阅读