django
MacOS
To be able to install Django, update Python and install MySQLdb module. Since installing software on OSX is not as easy as it should be, updating Python and installing MySQLdb is not as easy as it sounds.
Installing Homebrew
Homebrew is a package manager for MacOS, an alternative to MacPorts. You can install Homebrew using ruby and cURL:
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
You also need to have Xcode installed (for the compiler?).
After the install, add the Homebrew bin directory to your path, so that the
system knows where to look for apps installed with Homebrew. Append the
following line to ~/.profile
export PATH="/usr/local/bin:/usr/local/share/python:$PATH"
Note that /usr/local/bin/ has to be first to override the defaults. Because
commands in the .profile file are executed when the user logs in, it's a good
idea to reboot or logout after installing Homebrew. If you do not wish to
reboot right at this moment, you can do source ~/.profile to load the
commands from the file into the current terminal session.
Updating Python
# use homebrew
brew install python
After the brew command has finished, run which python to verify that the
newly installed python has been picked up; it should output
/usr/local/bin/python
To double-check, you can launch Python and check the version number:
% python2
Python 2.7.1 (r271:86832, Apr 15 2011, 12:11:58)
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Installing MySQL
If you're running any other version of MySQL, you should dump any databases that you want to keep to a file to back them up and shut down the MySQL server before proceeding.
MySQL header files are required to compile MySQLdb. If your MySQL doesn't come with header files (MAMP MySQL doesn't), install MySQL with Homebrew:
brew install mysql
Caveat: you must run mysql_install_db to create the initial databases.
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
If you don't, any attempt to launch MySQL will fail with a cryptic error message.
Also make sure you don't run mysql_install_db as root. Doing so will result in
mysqld not being able to read the database files and failing with the same
cryptic message.
If you want MySQL to start automatically at boot, follow the instructions from the output of the brew install command above.
Finally, launch the server and connect to it to verify that the installation went successfully:
mysql.server start
mysql -uroot
Installing MySQLdb module
Versions of MySQLdb prior to 1.2.3 required manual editing
of _mysql.c and site.cnf files. Later versions don't seem to require it,
but you might want to set the threadsafe option in site.cnf to False just
in case. Build it and install:
python setup.py build
python setup.py install
To verify that MySQLdb installed successfully, run the Python interpreter and
do import MySQLdb. The interpreter should return silently.
Installing Django (finally)
easy_install Django