- 网速较慢,设置使用清华大学开源软件镜像站,参考//www.greatytc.com/p/d5b2b3bd5a3e
pip3 install mysqlclient
- 提示需要安装VC++
为什么会出现这样的错误
Windows Python needs Visual C++ libraries installed via the SDK to build code, such as viasetuptools.extension.Extension
ornumpy.distutils.core.Extension
. For example, buildingf2py
modules in Windows with Python requires Visual C++ SDK as installed above. On Linux and Mac, the C++ libraries are installed with the compiler.
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
- 查找对应的资源
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
其中cp27对应python2.7 win32表示window32位,win64表示windows64位系统。64位的不行安装32位的。
pip3 install mysqlclient-1.4.4-cp37-cp37m-win32.whl
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing f:\sydownload\mysqlclient-1.4.4-cp37-cp37m-win32.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.4.4
- 测试使用mysqlclinet
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> conn = MySQLdb.connect(host='localhost',port=3306,user='root',passwd='root',db='xxxx')
>>> cur = conn.cursor()
>>> cur.execute('select * from xxxxxxx;')
13
>>> cur.fetchall()
((2, '1BB1D9F3E1498E5CCBE899B451DE3548', 1551436800, 1553857200, 0, 0, '2357303'))...
参考:
https://www.scivision.dev/python-windows-visual-c-14-required/
http://swiftlet.net/archives/2987