Installing Django on OS X Leopard
If you haven’t already, stick your Leopard disk in and install Xcode 3.0.
Make a home for Django:
sudo mkdir /usr/local/django
cd /usr/local/django
Get the Django trunk from Subversion:
sudo svn co http://code.djangoproject.com/svn/django/trunk/
The Django trunk should now be in /usr/local/django/trunk/, and if you ever want to check out another branch, you have a nice spot to put it next to the trunk.
If you’ve previously install Python yourself, pay attention here
Find out if you’re using the right version of Python:
which python
If you don’t see:
/usr/bin/python
then delete whatever version you have sitting in your path, such as one in /usr/local/:
sudo rm /usr/local/bin/python
Once “which python” gives you “/usr/bin/python“, make sure your Python site-packages is in the right place. Running this command:
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
should give you:
/Library/Python/2.5/site-packages
End of previous Python caveat
Now make sure Python knows where to find Django:
ln -s /usr/local/django/trunk/django /Library/Python/2.5/site-packages/django
Put the django-admin.py script on your system path:
sudo ln -s /usr/local/django/trunk/django/bin/django-admin.py /usr/local/bin/
Now you should have Django installed and ready to go. Run:
django-admin.py startproject project_name
and see.
If it works, cd into the folder it creates and try:
python manage.py runserver
Then go to localhost:8000 in your browser.
Django + MySQL:
If you want to use MySQL with Django, there’s a bit more to do. If you have MySQL ready to go, continue. Otherwise, go talk with Dan for a bit and come back here when you’re done.
Download the MySQLdb package. Stick in in /usr/local/src if you’re cool. Open it and edit site.cfg.
Change line ~ 13 from:
#mysql_config = /usr/local/bin/mysql_config
To:
mysql_config = /usr/local/mysql/bin/mysql_config
In _mysql.c:
Remove these lines (~ 37-39):
#ifndef uint
#define uint unsigned int
#endif
Go to the folder on the command line, then:
sudo python setup.py build
sudo python setup.py install
You might have to run the build command more than once. Don’t ask me why–I’m a copy and paster just like you.
That should do it. Try editing your settings.py file in your Django project and entering information for a MySQL database and see if it works.
If you experience something different than this or have any problems, please let me know directly or leave a comment.
Comments
Cool. I’ll use this when I eventually try out Django. One thing though: how did it get in
/usr/local/src/django/trunk/instead of/usr/local/django/trunk?That was a typo. Thanks for catching that. It’s fixed now.
When I try to execute
django-admin.py startproject project_namei get a message reading:-bash: django-admin.py: command not foundI’m trying to get this running on a fresh install of Leopard. Any idea why it’s not working? I could really use some help.
@Jason - try this:
I’m getting:
-bash: cd: /usr/local/bin: Not a directoryYou need to create that directory and put it on your system path. I refer you to this article.
Got it. Thanks Trey!
after executing: ln -s /usr/local/django/trunk/django/bin/django-admin.py django-admin.py i get “file exists”
i then also get -bash: django-admin.py: command not found
after running django-admin.py startproject project_name .
Any ideas?
@Zach - What folder are you in when you are entering the
ln -scommand?I had an unsuccessful install of Python before, i cleaned it up and got it working. Now i cant get the MySQL module to function… not even sure the errors i am getting yet. THANKS
i get sudo: svn: command not found
i am on 10.4 with xcode installed. thanks.
Im going crazy here, maybe you can help. I installed django and everything through macports in the first tutorial i found. Later i realized that the version of python it installed was 2.4, i like the idea of being up to date with the latest. I followed your first couple commands and everything seems cool. I notice though that when i type python into the terminal it says “python 2.4.5″.
Then when i typed the next command:
I get:
Do you know how i can get it back to python 2.5 before moving forward with the rest of the installation tutorial.
Thanks to you or anyone that helps out in advance.
ps. I removed macports.
Trey:
You might want to add a trailing slash to this command:
As it won’t create the symlink properly - it’ll link
django-admin.pyto/usr/local/bininstead of/usr/local/bin/django-admin.pyAdded the trailing slash. Thanks, Phil.
What do you think about that?