简体   繁体   中英

Install mysqldb on snow leopard

I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard and have mysql installed natively it is not part of MAMP or similar. Please can some tell me where I need to start and what steps I need to follew I would be most grateful.

Thanks

On MAC OS X 10.6, Install the package as usual. The dynamic import error occurs because of wrong DYLD path. Export the path and open up a python terminal.

$ sudo python setup.py clean

$ sudo python setup.py build

$ sudo python setup.py install

$ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

$python

import MySQLdb

Now import MySQLdb should work fine.

You may also want to manually remove the build folder, before build and install. The clean command does not do a proper task of cleaning up the build files.

I'd recomend installing macports (latest svn trunk) and installing mysql from there.

sudo port install mysql5-server

Download the MySQL-python-1.2.2 source

make sure /opt/local/lib/mysql5/bin is in your path or edit site.cfg to include:

mysql_config = /opt/local/lib/mysql5/bin/mysql_config

Comment out line 38 of _mysql.c

// #define uint unsigned int

Then run:

sudo python setup.py install

should be all good.

[Partial Answer]

You'll have more fun pulling out your teeth. MySQL/Django/Mac is a disaster. This is the farthest I've gotten:

Get MySQLDB 1.2.3 Go into that and modify setup_posix.py:

Change:

mysql_config.path = "mysql_config"

To (depending on the version number of your MySQL):

mysql_config.path = "/usr/local/mysql-5.1.34-osx10.5-x86_64/bin/mysql_config"

python setup.py build python setup.py install

Here's a good article

First and foremost, make sure that XCode is installed. Without XCode, many pieces of the built-in Apache2 server important to developers are missing; most notably, the GNU Compiler Collection , which I would think to be requisite for MySQL bindings.

You could make your life a lot easier (especially on Lion) by just installing Mariadb instead:

http://mariadb.org/

It's a drop-in replacement for MySQL and is plug&play on OSX. The only thing you don't get is the MySQL system setting.

  1. Xcode was installed.

  2. Follow these instructions for setting up apache/php/mysql:

    http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

  3. I installed the free 32-bit version of EPD (this is optional but I wanted numpy/scipy).

  4. Make sure you have these lines in your ~/.profile (the second line is only if you installed EPD):

     export PATH=/usr/local/mysql/bin/:/usr/local/bin:/usr/local/sbin:$PATH export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}" 
  5. Downloaded mysqldb and run:

     python setup.py build sudo python setup.py install 
  6. Install the official release of Django or web2py. Everything worked after that. You can try the "Writing Your First Django App, Part 1" to test it out where in settings.py use:

     DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'Django Polls' DATABASE_USER = '*****' DATABASE_PASSWORD = '*****' DATABASE_HOST = '127.0.0.1' DATABASE_PORT = '3306' 
  7. I also use Navicat Lite and Sequel Pro for working with MySQL.

  8. Pydev is a nice IDE to use with Django.

  1. Install the newest 64bit DMG version of MySQL. Remember to backup your databases if you already have MySQL installed.
  2. enter this line in terminal:

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

  3. Edit the file setup_posix in the mysql-python installation directory.

Change the line

mysql_config.path = "mysql_config"

to

mysql_config.path = "/usr/local/mysql/bin/mysql_config"
  1. Myslq-Python needs a 64bit Version of Python. The new Python 2.7 64bit version creates an alias in /usr/local/bin/python.
  2. Enter the following lines in the mysql-python folder

    sudo /usr/local/bin/python setup.py clean

    sudo ARCHFLAGS="-arch x86_64"

    sudo /usr/local/bin/python setup.py build

    sudo /usr/local/bin/python setup.py install

And finally try it out:

python
import MySQLdb

One of the key things here is to make sure you're running both MySQL and the Python adaptor in 64 bit. The default Python 2.6.1 install on Snow Leopard is 64 bit so you must install MySQL in 64 bit and build the MySQLdb adapter in 64 bit.

  1. Make sure you have the latest Xcode installed
  2. Install 64-bit MySQL from DMG - http://dev.mysql.com/downloads/mirror.php?id=401941#mirrors
  3. Download MySQL-python-1.2.3 from http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
  4. Extract and make the following edit to site.cfg:

     mysql_config = /usr/local/mysql/bin/mysql_config 
  5. Then from your terminal run

     ARCHFLAGS="-arch x86_64" python setup.py build sudo python setup.py install 

You should then open a Python shell and type:

import MySQLdb

If you don't get any errors you're golden.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM