mysql-python:在Mac OS X上构建一个完全独立的_mysql.so? [英] mysql-python: building a completely standalone _mysql.so on Mac OS X?

查看:118
本文介绍了mysql-python:在Mac OS X上构建一个完全独立的_mysql.so?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VMware VM下运行Linux VM(Ubuntu 9.10)中的数据库服务器,但在Mac端编写Django。安装mysql-python需要在Mac上安装MySQL,用于将 _mysql.so 编译到 site-packages p>

但是,在这之后,我没有进一步使用在Mac的MySQL,而是宁愿删除它。当然,当_mysql.so需要 /usr/local/mysql/lib/libmysqlclient_r.16.dylib 时,这是不可能的。



在mysql-python的 site.cfg 中有一个static选项,当设置为true时,会显着增加 _mysql.so 文件,但仍然取决于.dylib。



方法使.so完全独立于MySQL是否安装,即使这意味着使文件庞大吗?



解决方案,如果存在,应该工作10.5和10.6,因为我将在不同的机器上使用这两个版本的时间。

解决方案

出了自己后一点挖。这很简单,实际上;我会在这里记录解决方案,以防有人需要它:


  1. 从mysql.com获取MySQL的源tarball而不是特定于平台的二进制tarball)


  2. 解压缩,运行 ./ configure 你的目的,但你需要 - enable-static 。为了确定,我包括 - disable-shared ,虽然它可能不是绝对必要的。我使用以下方法,您的其他方面可能会有所不同:


    $ ./configure --prefix = / usr / local / mysql-src / --enable-static --disable-shared --with-charset = utf8 --with-extra-charsets = ascii,binary,latin1 --with- collat​​ion = utf8_general_ci

    $ make

    $ sudo make install


    (关于这里的字符集和排序规则参数:在这种情况下,它们可能完全不必要,因为我之后要删除MySQL,因为所有的客户端连接使用一些charset /排序规则,我覆盖我的基础UTF-8 -wise只是为了防止MySQLdb使用的默认字符集/排序规则受 _mysql.so 编译 - 更聪明的男人比我可能想要确认这种方式或其他。)


  3. 获取最新的源码tarball的mysql-python从 http://pypi.python.org/pypi/MySQL-python p>


  4. 打开它,并在 site.cfg 中设置 static = True mysql_config = / usr / local / mysql-src / bin / mysql_config (或在配置期间选择的任何路径)。


  5. 运行 python setup.py build 。一些与架构相关的错误可能会出现在编译结束时,但可以忽略。


  6. 运行 sudo python setup.by安装。这会在 site-packages 目录中创建一个.egg文件并将其添加到easy_install.pth文件中。


  7. p>你完成了!您现在可以删除MySQL的所有痕迹以及mysql-python源。该蛋可以复制为其他Mac运行相同版本的OS X.我很高兴地将它复制到使用 virtualenv 创建的各种虚拟环境。 / p>

这适用于10.5,我很快就会在10.6上测试,如果需要以不同的方式完成,结果在这里。


I'm running a database server in a Linux VM (Ubuntu 9.10) under VMware Fusion, but coding Django on the Mac side. Installing mysql-python requires that MySQL is installed on the Mac for compiling _mysql.so into site-packages.

However, after this is done, I have no further use for MySQL on the Mac side, and would rather just delete it. Of course, this is not possible when _mysql.so requires /usr/local/mysql/lib/libmysqlclient_r.16.dylib.

There is a "static" option in mysql-python's site.cfg, which, when set to "true", significantly increases the size of the _mysql.so file, but it still depends on the .dylib.

Is there a way of making the .so completely independent of whether MySQL is installed or not, even if that means making the file enormous?

The solution, if one exists, should work on both 10.5 and 10.6, since I'll be using both versions on different machines for the time being.

解决方案

Never mind, found out myself after a bit more digging. It's pretty simple, actually; I'll record the solution here in case someone else needs it:

  1. Get the source tarball of MySQL from mysql.com (not the platform-specific binary tarball)

  2. Unpack it, run ./configure with whatever options suit your purposes, but you will require --enable-static. Just to be sure, I included --disable-shared, though it might not be strictly necessary. I used the following, yours might differ on other counts:

    $ ./configure --prefix=/usr/local/mysql-src/ --enable-static --disable-shared --with-charset=utf8 --with-extra-charsets=ascii,binary,latin1 --with-collation=utf8_general_ci
    $ make
    $ sudo make install

    (Regarding the charset and collation parameters here: they may be completely unnecessary in this use case, since I'm going to delete MySQL afterwards, but since all the client connections use some charset/collation, I'm covering my bases UTF-8 -wise just in case the default charset/collation used by MySQLdb is affected by how _mysql.so is compiled -- wiser men than I may want to confirm this one way or the other.)

  3. Get the latest source tarball of mysql-python from http://pypi.python.org/pypi/MySQL-python

  4. Unpack it, and in site.cfg set static = True and mysql_config = /usr/local/mysql-src/bin/mysql_config (or whatever path you chose during configure).

  5. Run python setup.py build. Some architecture-related errors may appear at the end of the compile, but they can be ignored.

  6. Run sudo python setup.by install. This creates an .egg in your site-packages directory and adds it to the easy_install.pth file.

  7. You're done! You may now delete all traces of MySQL as well as the mysql-python sources. The egg can be copied as-is to other Macs running the same version of OS X. I'm happily copying it to various virtual environments created with virtualenv as we speak.

This worked on 10.5, I'll test it on 10.6 soon and, if something needs to be done differently, report the results here.

这篇关于mysql-python:在Mac OS X上构建一个完全独立的_mysql.so?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆