在 Windows 中将 MySQL 与 Python 集成
我发现在我的 Windows 系统中很难将 MySQL 与 Python 结合使用.
我目前使用的是 Python 2.6.我尝试使用提供的安装脚本编译 MySQL-python-1.2.3b1(它应该适用于 Python 2.6?)源代码.安装脚本运行,它不报告任何错误,但它不生成 _mysql 模块.
我也尝试过为 Python 2.5 设置 MySQL,但没有成功.使用 2.5 的问题是 Python 2.5 是用 Visual Studio 2003 编译的(我使用提供的二进制文件安装了它).我的 Windows 系统上有 Visual Studio 2005.因此 setuptools 无法生成 _mysql 模块.
有什么帮助吗?
解决方案python-mysqldb 的下载页面.该页面包括 Python 2.5、2.6 和 2.7 的 32 位和 64 位版本的二进制文件.
还有关于摆脱弃用警告的讨论.>
更新:这是一个旧答案.目前,我建议使用 PyMySQL.它是纯python,所以它同样支持所有操作系统,它几乎是mysqldb的直接替代品,它也适用于python 3.安装它的最佳方法是使用pip.您可以从此处安装它(更多说明这里),然后运行:
pip install pymysql
I am finding it difficult to use MySQL with Python in my windows system.
I am currently using Python 2.6. I have tried to compile MySQL-python-1.2.3b1 (which is supposed to work for Python 2.6 ?) source code using the provided setup scripts. The setup script runs and it doesn't report any error but it doesn't generate _mysql module.
I have also tried setting up MySQL for Python 2.5 with out success. The problem with using 2.5 is that Python 2.5 is compiled with visual studio 2003 (I installed it using the provided binaries). I have visual studio 2005 on my windows system. Hence setuptools fails to generate _mysql module.
Any help ?
解决方案Download page for python-mysqldb. The page includes binaries for 32 and 64 bit versions of for Python 2.5, 2.6 and 2.7.
There's also discussion on getting rid of the deprecation warning.
UPDATE: This is an old answer. Currently, I would recommend using PyMySQL. It's pure python, so it supports all OSes equally, it's almost a drop-in replacement for mysqldb, and it also works with python 3. The best way to install it is using pip. You can install it from here (more instructions here), and then run:
pip install pymysql
相关文章