Python django 安装 mysqlclient 失败

使用命令安装失败:

C:Program Files (x86)PythonPython37-32Scripts>pip3.7.exe install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    ERROR: Complete output from command 'c:program files (x86)pythonpython37-32python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\Users\Wayde\AppData\Local\Temp\pip-install-q0t7bxx3\mysqlclient\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersWaydeAppDataLocalTemppip-record-6afkxr9minstall-record.txt' --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    creating build
    creating buildlib.win32-3.7
    creating buildlib.win32-3.7MySQLdb
    copying MySQLdb\__init__.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdb\_exceptions.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbcompat.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbconnections.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbconverters.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbcursors.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdb
elease.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdb	imes.py -> buildlib.win32-3.7MySQLdb
    creating buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstants\__init__.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsCLIENT.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsCR.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsER.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsFIELD_TYPE.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsFLAG.py -> buildlib.win32-3.7MySQLdbconstants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build	emp.win32-3.7
    creating build	emp.win32-3.7Release
    creating build	emp.win32-3.7ReleaseMySQLdb
    C:Program Files (x86)Microsoft Visual Studio2017ProfessionalVCToolsMSVC14.16.27023inHostX86x86cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb" "-Ic:program files (x86)pythonpython37-32include" "-Ic:program files (x86)pythonpython37-32include" "-IC:Program Files (x86)Microsoft Visual Studio2017ProfessionalVCToolsMSVC14.16.27023ATLMFCinclude" "-IC:Program Files (x86)Microsoft Visual Studio2017ProfessionalVCToolsMSVC14.16.27023include" "-IC:Program Files (x86)Windows KitsNETFXSDK4.6.1includeum" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0ucrt" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0shared" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0um" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0winrt" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0cppwinrt" /TcMySQLdb/_mysql.c /Fobuild	emp.win32-3.7ReleaseMySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command "'c:program files (x86)pythonpython37-32python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\Users\Wayde\AppData\Local\Temp\pip-install-q0t7bxx3\mysqlclient\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersWaydeAppDataLocalTemppip-record-6afkxr9minstall-record.txt' --single-version-externally-managed --compile" failed with error code 1 in C:UsersWaydeAppDataLocalTemppip-install-q0t7bxx3mysqlclient

解决方法:

到这个网站下载自己对应的版本到本地,然后进行安装 :

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient 

C:Program Files (x86)PythonPython37-32Scripts>pip3.7.exe install F:Downloadsmysqlclient-1.4.2-cp37-cp37m-win32.whl
Processing f:downloadsmysqlclient-1.4.2-cp37-cp37m-win32.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.4.2

安装成功

原文地址:https://www.cnblogs.com/zoneofmine/p/10801128.html