Mac OSX安装 Django MySQL mysqlclient

Mac

Python36

$ brew install mysql-connector-c 
$ pip3 install mysqlcient # 报错找不到OSError: mysql_config not found
$ cd /usr/local/Cellar/mysql-connector-c/6.1.11/bin
$ cp mysql_config mysql_config.bak
$ chmod u+w mysql_config # 文件114行从libs="$libs -l "修改为libs="$libs -lmysqlclient -lssl -lcrypto"
$ pip3 install mysqlcient

Python37

# Python3.7如上修改后报错ld: library not found for –lssl”和ld: library not found for -lcrypto,所以删除ssl和crypto即可

另外,Mac中mysqlclient 包在国内 pip 源比如清华中是没有的,不过默认的有。

Linux

不需要 mysql-connector-c,而是需要安装 python3-dev(apt-get)或者 python36-devel(rpm),否则报错MySQLdb/_mysql.c:37:20: fatal error: Python.h: No such file or directory。Rpm 当前只有36最新,还没有37。

$ yum search python3 | grep devel  # 搜索确认选择使用的Python 版本
$ yum install python36-devel  # 报错python36-libs-3.6.6-2.el7.x86_64 conflicts with file from package python36u-libs-3.6.7-1.ius.centos7.x86_64
$ yum remove python36u-libs-3.6.7  # 安装 python36-devel时会依赖安装python36-libs-3.6.6
$ pip3 install mysqlclient

你可能感兴趣的:(DevOps)