python2.7下安装mysql-python
http://blog.csdn.net/xxm524/article/details/48754139
一定要注意安装版本,由于版本错误,浪费好久好久的时间
错误:
_mysql.pyd : fatal error LNK1120: 56 unresolved externals
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.
exe"' failed with exit status 1120
原因是VCForPython27.msi安装的32位,但是python是64位的。重新下载32位的python安装包,安装后再pip install mysql。正常。
windows系统python35 安装mysql-python
解决方案:
搜索半天,最终发现,python3不支持mysql-python了,多么痛的领悟啊!!!
安装第三方包pymysql。下载地址:https://pypi.python.org/pypi/PyMySQL#downloads
使用方法:
import pymysql as MySQLdb
django 中使用方法,在项目settings.py目录里的init.py加入
import pymysql
pymysql.install_as_MySQLdb()
解决过程:
- 错误一:error: Unable to find vcvarsall.bat
**错误1:Microsoft Visual C++ 14.0 is required. **
从错误提示的url下载,下载后安装visualcppbuildtools_full
安装遇到错误:
百度搜索Microsoft Visual C++ 14.0 下载,在脚步之家下载的,约12M,安装成功。再次执行安装mysql-python,还是报错。
后又重新回到在线安装居然可以成功,这次选择的是自定义安装,勾选了win10 sdk和.net framework两个,安装空间居然需要8G,心疼。然后就是漫长的等待,第一次安装失败很有可能是网络原因。
安装完后,执行python setup.py install,报错:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\users\michaelzeng\appdata\local\programs\python\python36\include -Ic:\users\michaelzeng\appdata\local\programs\python\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" /Tc_mysql.c /Fobuild\temp.win-amd64-3.6\Release\_mysql.obj /Zl
_mysql.c
c:\users\michaelzeng\appdata\local\programs\python\python36\include\pyconfig.h(222): fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
win10 sdks重装为win 8 sdks,再次执行,错误变为:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -IC:\Users\michaelzeng\AppData\Local\Programs\Python\Python36\include -IC:\Users\michaelzeng\AppData\Local\Programs\Python\Python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.6\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(42): fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
安装mysql connector, 下载地址:https://dev.mysql.com/downloads/connector/python/
我的系统为64, 下载的是mysql-connector-python-2.1.5-py3.4-winx64,还是报错,后来注意到寻找的目录是Program Files (x86),又下了个32位的安装。错误过去了。但是又来新的错误:
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup
build\lib.win-amd64-3.5\_mysql.cp35-win_amd64.pyd : fatal error LNK1120: 56 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120
搜索半天,最终发现,python3不支持mysql-python了,多么痛的领悟啊!!!
安装第三方包pymysql。下载地址:https://pypi.python.org/pypi/PyMySQL#downloads
使用方法:
import pymysql as MySQLdb