使用Python在OSX上写入MySQL的设置更容易 [英] Easier setup for writing to MySQL on OSX with Python

查看:72
本文介绍了使用Python在OSX上写入MySQL的设置更容易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python脚本,它使用 mysql-python 写入MySQL数据库.对于Linux和Windows来说,这很好,但是在OSX上,对于我的客户来说,该库太难安装了.

I have a Python script that writes to a MySQL database using mysql-python. This is fine for Linux and Windows but on OSX this library is too difficult for my clients to install.

需要编辑配置文件,目录符号链接,安装gcc,xcode,...
非技术用户的压倒性过程.

Requires editing configuration files, directory symlinks, installing gcc, xcode, ...
An overwhelming process for non-technical users.

那么,有没有更实用的方法来支持在OSX上写MySQL?

So, is there a more practical way to support writing to MySQL on OSX?

一些潜在的替代方法:

  • https://github.com/petehunt/PyMySQL
  • http://www.egenix.com/products/python/mxODBC/
  • http://code.google.com/p/pyodbc/
  • https://launchpad.net/myconnpy
  • http://sourceforge.net/projects/mypysql/

推荐答案

不幸的是,目前确实没有任何简单的解决方案.如果您需要将MySQL与Python一起使用,则OS X上最简单,最可靠的解决方案是安装所有内容-Python,MySQLdb,所需的任何其他第三方Python软件包,MySQL客户端库以及(如果需要的话)MySQL服务器库和实用程序-使用包管理系统,例如 MacPorts .尝试从不同来源安装各种组件时,经常会遇到不兼容构建的可执行文件和库的问题:32位与64位,不同的ABI(10.3与10.6)等.

Unfortunately, there really is no trivial solution at the moment. If you need to use MySQL with Python, the simplest and most reliable solution on OS X is to install everything - Python, MySQLdb, any other third-party Python packages needed, MySQL client libraries, and, if necessary, MySQL server libraries and utilities - using a package management system, like MacPorts. Trying to install the various components from different sources frequently runs into problems with incompatibility-built executables and libraries: 32-bit vs 64-bit, different ABIs (10.3 vs 10.6) etc.

对于装有Xcode和 MacPorts基本系统的系统,您可以构建和安装所有内容一个命令:

For a system with Xcode and the MacPorts base system installed, you can build and install everything with one command:

sudo port install py27-mysql

如果您还需要MySQL服务器:

If you need the MySQL server as well:

sudo port install py27-mysql mysql5-server

默认情况下,所有安装了MacPorts的可执行文件都将安装在/opt/local中,因此您只需要从此处运行即可:

All MacPorts-installed executables will be installed by default in /opt/local, so you just need to run things from there:

/opt/local/bin/python2.7

为使您的用户更容易使用,您应该能够使用MacPorts将必要的端口集构建为二进制归档文件,并设置脚本以安装MacPorts基本系统,然后安装预构建的软件包. 《 MacPorts指南》的此处中提供了有关此信息.但是,其中的大多数对于MacPorts 2.0.x而言都是过时的.在《指南》更新之前,此处 .最安全的方法是为每个受支持的OS X版本构建一组不同的软件包. 可能可以在所需的最旧系统上构建一个向上兼容的集合:例如,在10.5上构建软件包,这些软件包也可以在10.6和10.7系统上运行.为了避免干扰客户的MacPorts安装,您还可以从源代码构建MacPorts基本系统,并将安装根目录更改为/opt/local以外的其他名称.

To make it easier for your users, you should be able to use MacPorts to build the set of necessary ports as binary archives and set up a script to install the MacPorts base system and then your pre-built packages. There is some info on this in the MacPorts Guide here. However, much of that is out-of-date for MacPorts 2.0.x. Until the Guide is updated, there is information starting here. The safest approach would be to build a different set of packages for each OS X release supported. It might be possible to build one upward-compatible set on the oldest system needed: say, build packages on 10.5 that would also work on 10.6 and 10.7 systems. To prevent interference with customer MacPorts installations, you could also build the MacPorts base system from source and change the installation root to something other than /opt/local.

在OS X上,更惯用的方法是使用 py2app 创建应用程序包其中包括Python和MySQL客户端库.我不知道是否有人成功做到了.

A more idiomatic approach on OS X would be to use py2app to create an application bundle that includes Python and the MySQL client libraries. I don't know if anyone has successfully done that.

另一个建议:如果您确实不需要远程服务器,请考虑使用SQLite. 对SQLite的支持包含在Python标准库中.

Another suggestion: if you don't really need a remote server, consider using SQLite instead. Support for SQLite is included in the Python Standard Library.

这篇关于使用Python在OSX上写入MySQL的设置更容易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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