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 条评论
登录 后参与评论

相关文章

来自专栏技术翻译

简单的Apache NiFi操作仪表板(第2部分):Spring Boot

要访问要在我们的仪表板中显示的数据,我们将使用一些Spring Boot 2.06 Java 8微服务在Hadoop 3.1上调用HDP 3.0中的Apache...

1306
来自专栏iOS开发攻城狮的集散地

iOS app国际化 、跳转到系统设置、iOS10通知、正则表达式

1404
来自专栏24K纯开源

Mac OS X平台下QuickLook开发教程

一、引言       Quick Look技术是Apple在Mac OS X 10.5中引入的一种用于快速查看文件内容的技术。用户只需要选中文件单击空格键即可快...

2378
来自专栏程序猿

Unicode 码对应的键盘

A A键-65 Add 加号键 107 Alt ALT组合键 262144 Apps 应用程序...

3359
来自专栏张善友的专栏

Mono 3.0 beta 正式发布

Mono 老大Miguel de Icaza 在博客上宣布了Mono 3.0的发布,这还是一个beta版本的发布,并不是正式发布,所以在运营环境还是要慎重使用,...

17510
来自专栏Keegan小钢

App项目实战之路(五):服务端篇

近一个月因为忙于其他事情,一直没能抽出时间来更新项目进度。现在,只能趁着国庆期间,赶紧抽空更新下进度。这次,我想简单谈谈服务端的一些东西。

1056
来自专栏Java后端技术

spring-boot-starter大力出奇迹

​  上篇文章我们已经聊了SpringBoot的启动过程中的各类扩展点,那么从http://start.spring.io上我们生成的demo项目中,到目前就剩...

902
来自专栏iOS Developer

一点一滴慢慢的揭开XMPP的神秘面纱

1131
来自专栏乐沙弥的世界

使用 runcluvfy 校验Oracle RAC安装环境

--*****************************************

792
来自专栏Flutter入门到实战

Android适配全面总结(三)----ROM适配

版权声明:本文为博主原创文章(部分引用他人博文,已加上引用说明),未经博主允许不得转载。https://www.jianshu.com/p/f9c67a4b90...

901

扫码关注云+社区