背景
折腾:
【记录】使用Python操作MySQL数据库
的过程中,需要去安装MySQLdb。
下载MySQLdb
去官网:
http://pypi.python.org/pypi/MySQL-python/
看到有1.2.4和1.2.3
所以去最新的1.2.4:
http://pypi.python.org/pypi/MySQL-python/1.2.4
下载对应的编译好的版本:
MySQL-python-1.2.4.win32-py2.7.exe
得到1MB的
MySQL-python-1.2.4.win32-py2.7.exe
安装MySQLdb
双击安装:
结果出错:
看来此x86的exe,是不支持我的win7 x64。
所以只能去下载源码再去安装了。
下载源码:
MySQL-python-1.2.4.zip
然后再去解压和安装,结果果然出现
error: Unable to find vcvarsall.bat
的错误:
D:\tmp\dev_tools\python\mysql\MySQL-python-1.2.4\MySQL-python-1.2.4>setup.py install Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz Extracting in c:\users\cli\appdata\local\temp\tmpkapo0l Now working in c:\users\cli\appdata\local\temp\tmpkapo0l\distribute-0.6.28 Building a Distribute egg in D:\tmp\dev_tools\python\mysql\MySQL-python-1.2.4\MySQL-python-1.2.4 D:\tmp\dev_tools\python\mysql\MySQL-python-1.2.4\MySQL-python-1.2.4\distribute-0.6.28-py2.7.egg running install running bdist_egg running egg_info writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt reading manifest file ‘MySQL_python.egg-info\SOURCES.txt’ reading manifest template ‘MANIFEST.in’ writing manifest file ‘MySQL_python.egg-info\SOURCES.txt’ installing library code to build\bdist.win-amd64\egg running install_lib running build_py creating build creating build\lib.win-amd64-2.7 copying _mysql_exceptions.py -> build\lib.win-amd64-2.7 creating build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\__init__.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\converters.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\connections.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\cursors.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\release.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\times.py -> build\lib.win-amd64-2.7\MySQLdb creating build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\CR.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\ER.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-2.7\MySQLdb\constants running build_ext building ‘_mysql’ extension error: Unable to find vcvarsall.bat D:\tmp\dev_tools\python\mysql\MySQL-python-1.2.4\MySQL-python-1.2.4> |
然后参考之前的办法,结果还是出错:
D:\tmp\dev_tools\python\mysql\MySQL-python-1.2.4\MySQL-python-1.2.4>SET VS90COMNTOOLS=%VS100COMNTOOLS% D:\tmp\dev_tools\python\mysql\MySQL-python-1.2.4\MySQL-python-1.2.4>setup.py install running install running bdist_egg running egg_info writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt reading manifest file ‘MySQL_python.egg-info\SOURCES.txt’ reading manifest template ‘MANIFEST.in’ writing manifest file ‘MySQL_python.egg-info\SOURCES.txt’ installing library code to build\bdist.win-amd64\egg running install_lib running build_py copying MySQLdb\release.py -> build\lib.win-amd64-2.7\MySQLdb running build_ext building ‘_mysql’ extension creating build\temp.win-amd64-2.7 creating build\temp.win-amd64-2.7\Release C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,4,’final’,1) -D__version__=1.2.4 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -ID:\tmp\dev_install_root\Python27_x64\include -ID:\tmp\dev_install_root\Python27_x64\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\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 10.0\VC\BIN\amd64\cl.exe"’ failed with exit status 2 D:\tmp\dev_tools\python\mysql\MySQL-python-1.2.4\MySQL-python-1.2.4> |
然后再参考:
Windows下安装MySQLdb遇到的问题及解决方法
所说的:
1)问题 : _mysql.c(34) : fatal error C1083: Cannot open include file: ‘config-win.h’: No such file or directory
error: command ‘”C:/Program Files/Microsoft Visual Studio 9.0/VC/BIN/cl.exe”‘ failed with exit status 2
原因 :原因是安装MySQL的时候没有安装C语言库。
解决 :重新运行MySQL的安装程序,选择Modify,把“C Include Files / Lib Files”勾选上,并安装。
去重新安装mysql。
总结
待续。。。。
转载请注明:在路上 » 【记录】为Python安装MySQL数据库模块:MySQLdb
Post Views: 970