Python:如何在Windows 7 x64上安装mysqldb?

18

我试图在 windows x64 上安装 Mysql-python

我已经安装了 x64 版本的 Pythonsetuptools(已在 leaf 库上检查并成功安装),但我无法安装 mysqldb。 我尝试执行以下命令:

C:\Users\Fedcomp\Desktop\leaf-0.4\MySQL-python-1.2.3>python setup.py install

但是遇到了以下问题:

In file included from _mysql.c:34:
D:\servers\xampp_server\xampp\mysql\include/config-win.h:211:1: warning: "finite
" redefined
D:\servers\xampp_server\xampp\mysql\include/config-win.h:164:1: warning: this is
 the location of the previous definition
D:\servers\xampp_server\xampp\mysql\include/config-win.h:277:1: warning: "HAVE_S
TDDEF_H" redefined
In file included from D:\Python27\include/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
D:\Python27\include/pyconfig.h:673:1: warning: this is the location of the previ
ous definition
error: command 'gcc' failed with exit status 1

尝试使用MSVC,但遇到以下问题(已安装MS Visual Express)

C:\Users\Fedcomp\Desktop\leaf-0.4\MySQL-python-1.2.3>python setup.py install bui
ld --compiler=msvc
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'
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
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
error: Unable to find vcvarsall.bat

如何在Windows x64上正确安装mysqldb? (来自原始MySQL安装的头文件,因为在xampp服务器中它们不存在)

或者有人能为Windows Python x64Python x86编译mysqldb吗?

3个回答

35

编辑: mysqlclientPyPI上有32位和64位的二进制包。它是MySQL-Python的一个分支,自2014年以来没有发布过新版本。

以下是为了典型而保留的原始回答:

你可以在这里(Python 2.6-3.2),这里(2.7)或者这里(2.6)找到二进制安装程序。请注意,在Windows x64上,你不一定要使用64位Python。你也可以使用32位的Python构建,因为有更多的预编译的第三方软件包可用。


+1 很好的建议。我支持使用32位。这确实会让生活更容易。 - David Heffernan
如果您已经安装了其他版本,我建议先卸载并安装正确的版本。 - Pritesh Patel
只是一个小评论:我尝试了第一个链接,它无法连接到我的数据库(适用于Python 2.7版本)。但是第二个链接的驱动程序运行良好。 - dbf
这太棒了,我花了很长时间才找到它。谢谢! - Trying_hard
这是一个好建议,但如果mysql数据库是64位的,则该驱动程序将无法与mysql一起使用。 - kta

2

我不是100%确定,但我认为你的路径变量有问题。看起来编译器找不到,运行vcvarsall.bat进行搜索并双击它,它应该能正确设置你的路径变量。然后再尝试安装你的软件包。 如果你找不到vcvarsall.bat,请重新安装MS Visual Express。


4
请尝试从此处下载预编译的x64版本MySQL-python:Python扩展包非官方Windows二进制文件 - user656781

1
"

"Unable to find vcvarsall.bat"意味着您的路径中没有必要的Visual Studio目录。

但是,如果您使用64位Python,则需要64位编译器,而Express不支持64位。您可以下载SDK MSVC编译器并进行配置,但这非常困难。

如果我是您,我会切换到32位Python,您几乎可以肯定地获得预构建的二进制文件。

编辑

由piquadrat发现的预构建的64位二进制文件将更加简单!

"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接