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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介: 以后博客更新在:https://oldpan.me有两个月没有碰django了,没想到一下从11.3升级到了2.0。django框架团队真的是很用心。

以后博客更新在:https://oldpan.me

有两个月没有碰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
  error: command 'clang' failed with exit status 1

又遇到了问题,经查询是没有安装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

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
22天前
|
Linux 数据库管理 Python
CentOS7编译安装Python3.10(含OpenSSL1.1.1安装),创建虚拟环境,运行Django项目(含sqlite版本报错)
CentOS7编译安装Python3.10(含OpenSSL1.1.1安装),创建虚拟环境,运行Django项目(含sqlite版本报错)
131 4
|
6月前
|
存储 Linux 数据安全/隐私保护
Python 教程之 Django(2)介绍和安装
Python 教程之 Django(2)介绍和安装
53 0
|
1月前
|
关系型数据库 MySQL 数据库
django4版本提示 django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.26)
在学习Django时,用户遇到`django.db.utils.NotSupportedError`,提示需要MySQL 8.0.25或更高版本,但其系统上是5.7.26。为解决这个问题,用户决定不升级MySQL,而是选择注释掉Django源码中的数据库版本检查。通过Python命令行找到Django安装路径,进入`db/backends/base/base.py`,注释掉`self.check_database_version_supported()`函数
460 0
|
1月前
|
Python
Django:构建 Web 应用的高级 Python 框架(二)安装 Django
Django:构建 Web 应用的高级 Python 框架(二)安装 Django
|
1月前
|
Python
PyCharm Community Edition 2023.3.1安装django模块
PyCharm Community Edition 2023.3.1安装django模块
|
7月前
|
Shell Python
02 Django入门 - 虚拟环境下安装django
02 Django入门 - 虚拟环境下安装django
41 0
|
1月前
|
存储 Linux Shell
Python 教程之 Django(2)介绍和安装
Python 教程之 Django(2)介绍和安装
35 0
Python 教程之 Django(2)介绍和安装
|
1月前
|
Python
Django 学习教程-介绍与安装
本章介绍了Django是什么,以及为什么使用Django和安装Django
49 1
Django 学习教程-介绍与安装
|
6月前
|
Linux Shell Swift
django(二)centos安装django3.2报错SQLite 3.8.3 or later is required (found 3.7.17)
我正在参加「掘金·启航计划」 Centos安装diango3.2框架请参照《django(一)ubuntu18.04安装框架》 在运行: 复制代码 python3 manage.py runserver 0.0.0.0:81 的时候报错: swift 复制代码 django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17). 报错的大体意思是:对sqlite最低版本的需求的3.8.3,但是现在只找到了3.7.17。
72 1
|
1月前
|
算法 Java Python
Python【算法中心 01】Web框架Django入门(安装+项目创建+应用创建+服务启动)Python搭建算法中心后台实例分享
Python【算法中心 01】Web框架Django入门(安装+项目创建+应用创建+服务启动)Python搭建算法中心后台实例分享
56 0