This site has moved, this is just for reference, please visit the current one.

P Bergqvist

Mac, Python 2.7, MySQL AND python-mysql

Published: april 19, 2011

Tags: django mac python windows


I'm switching jobs (again!) and upgrading from a Dell-Hell-windows-machine to a Macbook Pro, and so far it has been both love and hate. Love because of the magsafe power connector and because of the Appstore, hate because of the non-existent application installation tool like apt-get for Debian/Ubuntu.

This is a howto of how to get a working django-environment up and running. This includes:

  • Python 2.7
  • Mysql 5.5
  • Python-mysql
  • Pip
  • Virtualenv
  • Virtualenvwrapper
  1. Download and install python 2.7 from I chose the 64-bit version and it works just fine, but if you are using some odd Python-lib you may want to use the 32-bit version.
  2. Install MySQL from I chose the .dmg-image 5.5 for 64-bit. Just to install, and remember to install MySQLStartup-thingie
  3. Install Mysql-python
    Just get the latest version from (it's no top of the whole list) and extract.
    Step into the extracted directory, edited the file calles, and change the line

    mysql_config.path = "mysql_config"  
    mysql_config.path = "/usr/local/mysql/bin/mysql_config"  

    Install by running:
    python clean
    python build
    sudo python install

  4. Install pip
    Since Python 2.7 added itself to your PATH you get access to all it's tools without having to do anything, so just:
    easy_install pip
  5. Install virtualenv, virtualenvwrapper
    And now when pip installed, run:
    pip install virtualenv virtualenvwrapper 
  6. Fix path etc in .bash_profile
    No you just have to add a few lines to some of your shell-related configs so everything ties together, I have chosen to edit ~/.bash_profile since I'm the only one who's gonna use this. So, open up ~/.bash_profile and the gist you find at 
    # Location for MySQL
    export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

    # Virtualenvwrapper
    export WORKON_HOME=~/Envs
    source /Library/Frameworks/Python.framework/Versions/2.7/bin/

    # Adds mysql-tools
    export PATH=/usr/local/mysql/bin:$PATH

EDIT: As always with .bashrc, .bash_profile it's a mess to always get what you want, in my case I couldn't get PyCharm to get where mysql was located, so just move the line
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
to /etc/profile for example and this should be avalaible system wide instead. 

In this howto I used many other howtos, and here are a list of some of them, thank you all!

blog comments powered by Disqus

Copyright © 2012 Me. All rights reserved.