Easier Setup For Writing To Mysql On Osx With Python
Solution 1:
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.
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
If you need the MySQL server as well:
sudo port install py27-mysql mysql5-server
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
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
.
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.
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.
Post a Comment for "Easier Setup For Writing To Mysql On Osx With Python"