Jun 7

[原]在Windows 下安装 MySQL-python 1.2.5 晴

linuxing , 19:12 , 编程 » Python , 评论(0) , 引用(0) , 阅读(9304) , Via 本站原创 | |
    在Windows 下调试 Python 还是挺麻烦的。通过PyCharm 来安装个MySQL-python 的库都搞了大半天。分别尝试 1.2.3、1.2.4 和 1.2.5 都有不同的错误。+_+
    最后确定还是在 1.2.5 版本下来解决,需要解决的问题就是这个:
“Cannot open include file: 'config-win.h': No such file or directory” while installing mysql-python

上面是在 1.2.4 版本上的,后来在 1.2.5 上面应该是解决的。但实际上,1.2.5 在Windows 64 位环境下还是有问题的,原因见后面的说明。

安装步骤如下:
1.安装 Microsoft Visual C++ Compiler Package for Python 2.7
下载链接

2.安装 MySQL Connector C 6.0.2
下载链接

3.下载 MySQL-python 1.2.5 源码包
下载链接
源码包

4.解压源码包后,修改 site.cfg 文件。
实际上,如果你是在32 位系统上部署,那么通过pip install 安装MySQL-python 1.2.5 只需进行上面的依赖包安装即可。
但在 64 位环境中,就会提示“Cannot open include file: 'config-win.h'” 的错误。
原因就是 site.cfg 中写的 MySQL Connector C 为32 位版本。

原来的 site.cfg 文件内容如下:
引用
# http://stackoverflow.com/questions/1972259/mysql-python-install-problem-using-virtualenv-windows-pip
# Windows connector libs for MySQL. You need a 32-bit connector for your 32-bit Python build.
connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2

修改为:
引用
connector = C:\Program Files\MySQL\MySQL Connector C 6.0.2

5.运行 python setup.py install 即可安装完成。
引用
D:\MySQL-python-1.2.5>python 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
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
C:\Users\Hyphen\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.
0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5
,'final',1) -D__version__=1.2.5 "-IC:\Program Files\MySQL\MySQL Connector C 6.0.
2\include" -IC:\Python27\include -IC:\Python27\PC /Tc_mysql.c /Fobuild\temp.win-
amd64-2.7\Release\_mysql.obj /Zl
_mysql.c
C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\config-win.h(203) : warni
ng C4005: 'SIZEOF_OFF_T' : macro redefinition
        c:\python27\include\pyconfig.h(345) : see previous definition of 'SIZEOF
_OFF_T'
C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\config-win.h(301) : warni
ng C4005: 'HAVE_STDDEF_H' : macro redefinition
        c:\python27\include\pyconfig.h(685) : see previous definition of 'HAVE_S
TDDEF_H'
_mysql.c(287) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', poss
ible loss of data
_mysql.c(317) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', poss
ible loss of data
_mysql.c(470) : warning C4244: 'initializing' : conversion from 'Py_ssize_t' to
'int', possible loss of data
_mysql.c(1168) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', pos
sible loss of data
_mysql.c(1274) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', pos
sible loss of data
_mysql.c(1466) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl
e loss of data
_mysql.c(1468) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl
e loss of data
_mysql.c(1504) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl
e loss of data
_mysql.c(1506) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl
e loss of data
_mysql.c(1532) : warning C4018: '<' : signed/unsigned mismatch
_mysql.c(2302) : warning C4244: 'function' : conversion from '__int64' to 'long'
, possible loss of data
C:\Users\Hyphen\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.
0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO "/LIBPATH:C:\Program Files\
MySQL\MySQL Connector C 6.0.2\lib\opt" /LIBPATH:C:\Python27\libs /LIBPATH:C:\Pyt
hon27\PCbuild\amd64 kernel32.lib advapi32.lib wsock32.lib mysqlclient.lib /EXPOR
T:init_mysql build\temp.win-amd64-2.7\Release\_mysql.obj /OUT:build\lib.win-amd6
4-2.7\_mysql.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\_mysql.lib /MANIFESTFI
LE:build\temp.win-amd64-2.7\Release\_mysql.pyd.manifest
_mysql.obj : warning LNK4197: export 'init_mysql' specified multiple times; usin
g first specification
   Creating library build\temp.win-amd64-2.7\Release\_mysql.lib and object build
\temp.win-amd64-2.7\Release\_mysql.exp
_mysql.obj : warning LNK4217: locally defined symbol strncat imported in functio
n _mysql_row_to_dict
_mysql.obj : warning LNK4217: locally defined symbol strncpy imported in functio
n _mysql_row_to_dict
_mysql.obj : warning LNK4217: locally defined symbol sprintf imported in functio
n _mysql_ConnectionObject_repr
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\MySQLdb
copying build\lib.win-amd64-2.7\MySQLdb\connections.py -> build\bdist.win-amd64\
egg\MySQLdb
creating build\bdist.win-amd64\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\constants\CLIENT.py -> build\bdist.win-a
md64\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\constants\CR.py -> build\bdist.win-amd64
\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\constants\ER.py -> build\bdist.win-amd64
\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\constants\FIELD_TYPE.py -> build\bdist.w
in-amd64\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\constants\FLAG.py -> build\bdist.win-amd
64\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\constants\REFRESH.py -> build\bdist.win-
amd64\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\constants\__init__.py -> build\bdist.win
-amd64\egg\MySQLdb\constants
copying build\lib.win-amd64-2.7\MySQLdb\converters.py -> build\bdist.win-amd64\e
gg\MySQLdb
copying build\lib.win-amd64-2.7\MySQLdb\cursors.py -> build\bdist.win-amd64\egg\
MySQLdb
copying build\lib.win-amd64-2.7\MySQLdb\release.py -> build\bdist.win-amd64\egg\
MySQLdb
copying build\lib.win-amd64-2.7\MySQLdb\times.py -> build\bdist.win-amd64\egg\My
SQLdb
copying build\lib.win-amd64-2.7\MySQLdb\__init__.py -> build\bdist.win-amd64\egg
\MySQLdb
copying build\lib.win-amd64-2.7\_mysql.pyd -> build\bdist.win-amd64\egg
copying build\lib.win-amd64-2.7\_mysql_exceptions.py -> build\bdist.win-amd64\eg
g
byte-compiling build\bdist.win-amd64\egg\MySQLdb\connections.py to connections.p
yc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\CLIENT.py to CLIENT.p
yc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\CR.py to CR.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\ER.py to ER.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\FIELD_TYPE.py to FIEL
D_TYPE.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\FLAG.py to FLAG.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\REFRESH.py to REFRESH
.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\__init__.py to __init
__.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\converters.py to converters.pyc

byte-compiling build\bdist.win-amd64\egg\MySQLdb\cursors.py to cursors.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\release.py to release.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\times.py to times.pyc
byte-compiling build\bdist.win-amd64\egg\MySQLdb\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\_mysql_exceptions.py to _mysql_exceptio
ns.pyc
creating stub loader for _mysql.pyd
byte-compiling build\bdist.win-amd64\egg\_mysql.py to _mysql.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying MySQL_python.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying MySQL_python.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying MySQL_python.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\
EGG-INFO
copying MySQL_python.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INF
O
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\MySQL_python-1.2.5-py2.7-win-amd64.egg' and adding 'build\bdist.w
in-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing MySQL_python-1.2.5-py2.7-win-amd64.egg
Copying MySQL_python-1.2.5-py2.7-win-amd64.egg to c:\python27\lib\site-packages
Adding MySQL-python 1.2.5 to easy-install.pth file

Installed c:\python27\lib\site-packages\mysql_python-1.2.5-py2.7-win-amd64.egg
Processing dependencies for MySQL-python==1.2.5
Finished processing dependencies for MySQL-python==1.2.5

确认:
引用
D:\>python
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> print MySQLdb.__version__
1.2.5

安装成功。
Tags: ,
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]