本文记录了在Windows下用pip安装mysqlclient出现以下两种错误的解决方法:
1.error: Microsoft Visual C++ 14.0 is required
2.fatal error C1083: Cannot open include file: ‘my_config.h’
在windows下使用python的mysqlclient库,安装提示如下错误(注意要用管理员模式执行CMD命令行):
C:\Windows\system32>pip install mysqlclient error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
访问错误提示的网站地址却返回404,于是在Microsoft网站安装了最新的C++编译环境,再安装一下试试:
C:\Windows\system32>pip install mysqlclient
_mysql.c(29): fatal error C1083: Cannot open include file: 'my_config.h': No such file or directory
本以为顺利安装了,结果又是错误,应该是没有mysql的开发包,不想折腾了,上网一搜,原来可以到如下网站下载安装编译好的文件。
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
不过看了一下,有好几种版本,先查一下自己的系统支持哪种版本,然后下载对应的。
在Python交互环境里输入如下两行命令即可获得系统支持的版本信息:
from pip._internal.pep425tags import get_supported
get_supported()
C:\Windows\system32>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pip._internal.pep425tags import get_supported
>>> get_supported()
[('cp36', 'cp36m', 'win32'), ('cp36', 'none', 'win32'), ('py3', 'none', 'win32')
, ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('py36', 'none', 'any'), ('py
3', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', '
none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none'
, 'any')]
>>> exit()
根据提示,我在上面的网站下载了mysqlclient-1.4.2-cp36-cp36m-win32.whl这个版本,然后安装:
C:\Windows\system32>pip install "C:\Users\xxxx\Downloads\mysqlclient-1.4.2-cp36-cp36m-win32.whl"
Processing c:\users\xxxx\downloads\mysqlclient-1.4.2-cp36-cp36m-win32.whl
Installing collected packages: mysqlclient
Found existing installation: mysqlclient 1.3.12
Uninstalling mysqlclient-1.3.12:
Successfully uninstalled mysqlclient-1.3.12
Successfully installed mysqlclient-1.4.2
顺利安装成功!