Skip to content

Instantly share code, notes, and snippets.

@zeuxisoo
Created April 13, 2011 08:56
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save zeuxisoo/917222 to your computer and use it in GitHub Desktop.
Save zeuxisoo/917222 to your computer and use it in GitHub Desktop.
MAMP + Python-MySQLdb
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'
@dubiao
Copy link

dubiao commented Sep 22, 2013

what dose the mean of the step 3 of PART 3:
3. source activate

@blairkelsie
Copy link

Hi dubiao,

The activate command activates the virtual environment.

Virtual Env Documentation

@leeseawuyhs
Copy link

leeseawuyhs commented Sep 14, 2017

  1. Bugs: ModuleNotFoundError: No module named 'ConfigParser'

run:
python setup.py install
Show bugs:
python setup.py install Traceback (most recent call last): File "setup.py", line 13, in <module> from setup_posix import get_config File "/MyDatas/Environment/MySQL-python-1.2.5/setup_posix.py", line 2, in <module> from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser'

  1. Fixed
    Open file: setup_posix.py, you can see:
    from ConfigParser import SafeConfigParser
    Model ConfigParser not found.
    => change model: ConfigParser to configparser (Python 3.6)
    Or run command to copy module:
    sudo cp /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/configparser.py /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ConfigParser.py
    => You can review python version and fix some as above.
    Run:
    python setup.py install

The package MySQL-python installed.

@jrenouard
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment