macOS使用django安装mysqlclient遇到的问题(mysqlclient 1.3.3 or newer is required)

有两个月没有碰django了,没想到一下从11.3升级到了2.0。django框架团队真的是很用心。

最近需要使用django搭建一个网站,使用的数据库是mysql。 mac电脑里面已经安装好了mysql-5.7-community。 之前使用的python和mysql的链接模块是Pymysql,使用django-11.3版本的时候没有需要问题。但是重新更新了django到2.0,下载好之前的配置后(requests),运行程序发现这个问题:

mysqlclient 1.3.3 or newer is required; you have 0.7.11.None

好吧,连之前的Pymysql都不能用了,于是进行安装mysqlclient。 使用pip进行安装:

pip install mysqlclient

并没有那么顺利,立马进行报错:

sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 15, in <module>
  ...

原来是没有找到mysql_config命令,那就进行添加吧:

(my-virtual-env-3.6.2) guoyanzongdeMacBook-Pro:Web_Assignment oldpan$ PATH="$PATH":/usr/local/mysql/bin

(my-virtual-env-3.6.2) guoyanzongdeMacBook-Pro:Web_Assignment oldpan$ mysql_config
Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
Compiler: Clang 8.1.0
Options:
        --cflags         [-I/usr/local/mysql/include ]
        --cxxflags       [-I/usr/local/mysql/include ]
        --include        [-I/usr/local/mysql/include]
        --libs           [-L/usr/local/mysql/lib -lmysqlclient ]
        --libs_r         [-L/usr/local/mysql/lib -lmysqlclient ]
        --plugindir      [/usr/local/mysql/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [5.7.19]
        --libmysqld-libs [-L/usr/local/mysql/lib -lmysqld ]
        --variable=VAR   VAR is one of:
                pkgincludedir [/usr/local/mysql/include]
                pkglibdir     [/usr/local/mysql/lib]
                plugindir     [/usr/local/mysql/lib/plugin]

好了,mysql_config能用了,接下来进行安装吧:

(my-virtual-env-3.6.2) guoyanzongdeMacBook-Pro:Web_Assignment oldpan$ pip install mysqlclient-1.3.12.tar.gz 
Processing ./mysqlclient-1.3.12.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... error
  Complete output from command /usr/local/opt/pyenv/versions/3.6.2/envs/my-virtual-env-3.6.2/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/m7/1w3636y53qd6k5z6f1hzqhpc0000gn/T/pip-giyw6g30-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/m7/1w3636y53qd6k5z6f1hzqhpc0000gn/T/tmpj4_ingaepip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.12-x86_64-3.6
  copying _mysql_exceptions.py -> build/lib.macosx-10.12-x86_64-3.6
  creating build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  copying MySQLdb/compat.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb
  creating build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.12-x86_64-3.6/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.12-x86_64-3.6
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/local/mysql/include -I/usr/local/opt/pyenv/versions/3.6.2/include/python3.6m -c _mysql.c -o build/temp.macosx-10.12-x86_64-3.6/_mysql.o
  xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

又遇到了问题,经查询是没有安装xcode工具: 打开mac的终端:

xcode-select --install

过了一两分钟后,安装好了,现在再进行安装mysqlclient:

(my-virtual-env-3.6.2) guoyanzongdeMacBook-Pro:Web_Assignment oldpan$ pip install mysqlclient-1.3.12.tar.gz 
Processing ./mysqlclient-1.3.12.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... done
  Stored in directory: /Users/oldpan/Library/Caches/pip/wheels/d1/94/21/97409904f278ca3331b447b448a3e90757b24aa72ddc8e22f1
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.12

终于安装好了!

参考资料: 1、http://blog.csdn.net/kedongjun/article/details/51470506 2、http://blog.csdn.net/u014642465/article/details/73890308 3、https://www.cnblogs.com/roystime/p/6920489.html 4、https://www.cnblogs.com/njj10/p/7676123.html

此文由腾讯云爬虫爬取,文章来源于Oldpan博客

欢迎关注Oldpan博客公众号,持续酝酿深度学习质量文:

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

编辑于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏乐沙弥的世界

TNS-01201: Listener cannot find executablen 错误

    最近在启动监听器的时候收到了TNS-01201: Listener cannot find executable...的错误提示。这个错误还真是一个一直...

862
来自专栏数据库新发现

通过SQLNET.ora文件限制Ip地址访问

链接:http://www.eygle.com/archives/2008/01/sqlnetora_ip_limit.html

1393
来自专栏乐沙弥的世界

配置Oracle Gateway 12连接到SQL server 2014

最近的工作中需要基于Oracle连接到SQLserver2014,我们可以通过配置Gateway的方式来实现这个功能。这个Gateway的实质是透过dblink...

1102
来自专栏xingoo, 一个梦想做发明家的程序员

Oracle 监听器无法启动(TNS-12537,TNS-12560,TNS-00507)

Oracle启动监听报错,提示 连接中断 [oracle@localhost ~]$ lsnrctl start LSNRCTL for Linux: Ver...

25810
来自专栏乐沙弥的世界

记一次离奇的TNS-12545 TNS-12560 TNS-00515

      最近reportDB监听无法随系统自启动,现象比较怪异。因为该服务器上的另一个实例的监听可以正常启动,这个不能自启动实例的监听手动启动又是正常的。因...

1102
来自专栏杨建荣的学习笔记

一条细小的报警短信的处理(r6笔记第96天)

最近偶尔会收到一封报警短信,提示内容大体如下, xxxx,trc_directory (TNS-1190),log_directory(TNS-1190),Pl...

3638
来自专栏乐沙弥的世界

Oracle 11g RAC 环境下单实例非缺省监听及端口配置

      如果在Oracle 11g RAC环境下使用dbca创建单实例数据库后,Oracle会自动将其注册到缺省的1521端口及监听器。大多数情况下我们使用...

962
来自专栏iOSDevLog

提交 BookReader Framework 到 CocoaPodsBookReaderCocoaPods

https://github.com/kishikawakatsumi/BookReader

1322
来自专栏乐沙弥的世界

ORA-00119,ORA-00132 错误处理

最近系统启动时,收到了ORA-00119以及ORA-00132的错误,该错误实际上跟LISTENER有关,通常的处理办法是将spfile转储为pfile然后从...

992
来自专栏海天一树

小朋友学C++(21):命名空间

这里的第一行,#include好理解,iostream是输入输出流,包含了输入流istream和输出流ostream。 第二行using namespace s...

1074

扫码关注云+社区