MAMP 安裝 Python 和 MySQLdb


這篇是由我的 Gist 轉貼過來的.
所以不作解釋了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
1. Goto http://dev.mysql.com/downloads/mysql/
2. Select Platform: "Mac OS X"
3. Download mysql-5.5.11-osx10.6-x86.tar.gz
(Mac OS X ver. 10.6 (x86, 32-bit), Compressed TAR Archive)
4. Unzip it
5. Copy include folder into /Applications/MAMP/Library
6. Copy lib/* files into /Applications/MAMP/Library/lib

----
1. Goto http://sourceforge.net/projects/mysql-python/
2. Download MySQL-python-1.2.3.tar.gz
3. unzip it

----
1. virtualenv --no-site-package test
2. cd test/bin
3. source activate
4. lipo -remove x86_64 ./python -output ./python

----
1. export DYLD_LIBRARY_PATH=/Applications/MAMP/Library/lib
2. export ARCHFLAGS='-arch i386'

----
1. cd MySQL-python-1.2.3
2. vim setup_posix.py
3. search mysql_config.path
4. set the value to /Applications/MAMP/Library/bin/mysql_config
5. save and exit
6. python setup.py install

----
import _mysql

db = _mysql.connect(unix_socket="/Applications/MAMP/tmp/mysql/mysql.sock",db="mysql",user="root",passwd="root")

db.query("select version()")

result = db.use_result() / result = db.store_result()
result.fetch_row()

result.fetch_row(result.num_rows())
result.fetch_row()
result.data_seek(0)
result.fetch_row()

----
If import _mysql Got Reason: image not found

try:
export DYLD_LIBRARY_PATH=/Applications/MAMP/Library/lib
export ARCHFLAGS='-arch i386'