在 OSX 10.5 (Leopard) 安装 MySQL-Python

尝试安装了一下 MySQL-python,发现竟然编译不过去,在网上搜了一下,找到了一个 workaround,应该是作者疏忽了。

原文在:http://www.keningle.com/?p=11

需要下载源码自行编译,首先修改 _mysql.c,删除从 34 行开始的 3 行。

#ifndef uint
#define uint unsigned int
#endif

uint port = MYSQL_PORT;
uint client_flag = 0;

修改为

unsigned int port = MYSQL_PORT;
unsigned int client_flag = 0;

创建一个符号链接

$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

最后编译安装就可以了

$ python setup.py install

3 comments so far

  1. 清风 December 3, 2007 2:41 pm

    port install py-mysql
    就可以了:) macports还是很爽的

  2. Syd February 15, 2008 11:36 pm

    先按照这个方法安装,
    执行到 sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql 时候提示
    ln: /usr/local/mysql/lib/mysql: No such file or directory

    然后执行 python setup.py install时候仍然报错
    Traceback (most recent call last):
    File “setup.py”, line 16, in
    metadata, options = get_config()
    File “/Users/syd/Downloads/MySQL-python-1.2.2/setup_posix.py”, line 43, in get_config
    libs = mysql_config(”libs_r”)
    File “/Users/syd/Downloads/MySQL-python-1.2.2/setup_posix.py”, line 24, in mysql_config
    raise EnvironmentError, “%s not found” % mysql_config.path
    EnvironmentError: mysql_config not found

    尝试使用port安装后成功
    但是在import MySQLdb时候说找不到module

    晕死了,怎么会这么麻烦

  3. admin February 22, 2008 2:58 am

    我没有用 Ports 装,我是自己下 MySQL 安装了,应该路径和 Ports 里面的不太一样吧。

Leave a comment

Please be polite and on topic. Your e-mail will never be published.