How to install a development ready setup of Django on MacOS X 10.4 (Tiger).
Yep, step by step. I took the easiest possible track for installation – installing with SQLite support. Not what you’d probably want to do for any sort of production world, but lovely for quick development.
1) Install MacOS X developer tools.
You can download the tools online from Apple’s ADC site once you’ve registered. You probably have a copy on CD or DVD with your Mac installation media – pop the DVD in and look around for it.
2) Install DarwinPorts
Go to http://darwinports.org/downloads/ and click on the link to download DarwinPorts-1.2.1-10.4.dmg. Obviously this is only if you have MacOS X 10.4. Once it’s downloaded, open the disk image and install the package.
3) Update DarwinPorts and get all the software. Note – this step took about 2 hours on my MacBookPro to grab, compile, and install everything. YMMV.
I used the following commands in order:
sudo port -d selfupdate
sudo port install subversion
sudo port install sqlite3 py-sqlite python24
sudo port install py-docutils py-mx
THIS NEXT BIT IS A VERY IMPORTANT STEP:
You’ll want to add the following environment variables. Open or create the file .bash_profile in your home directory and add the following lines at the end of that file:
PYTHONBIN=/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin
export PATH=/opt/local/bin:/opt/local/sbin:$PYTHONBIN:$PATH
Once that’s done, close the terminal window and open a new one. To test to make sure you’ve got the right PATH setup, run the command “python -V”. (thats a capital V). If you see version 2.4.something, you’re good. If you see version 2.3.something then you’re running the built in python and something forward is likely to break. Check the lines above in your .base_profile file to make sure the PATH environment variable is being updated properly.
Download Django for installation. Most folks will tell you to get the trunk from subversion – here’s what I did to get that:
cd ~
svn co http://code.djangoproject.com/svn/django/trunk django-trunk
cd django-trunk
sudo python setup.py install
Now you’ve got it installed. Issuing the command “django-admin.py” from the terminal window you have open should do something! (give you messages about how to use it)
Thanks for the instructions! I’ve been meaning to set up a local install for a while now, and I’ll definitely make use of these when I do it.
LikeLike
The documentation says you shouldn’t do a “setup.py install” for the development version. (http://www.djangoproject.com/documentation/install/)
Just add a symlink:
sudo ln -s `pwd`/django_src/django /opt/local/lib/python2.4/site-packages/django
That way you can easily update the django development version with a ‘svn update’ in ~/django-src/.
LikeLike
Ok, now I know I’m going nuts. I have made a HUGE problem on my computer, but I have no idea how, so I’m going to ask here. In Terminal.appls and then hit enter, I get-bash: ls: command not foundand typingsudo port -d selfupdateI get back:-bash: sudo: command not foundDo you (or anyone) have any idea how I could have broken this?
LikeLike
Olt: I specifically chose the “install” route because I don’t maintain complete consistency with the trunk – I found the permutations were more than I wanted to deal with while learning Django. So I installed one version and stuck there, upgrading only when I felt I was ready. For the record, I’m still on 0.91 actually. Looking forward to 0.95 – but I’m waiting for a release.
Kevin: Chances are your path is messed up. Open the Terminal.app and issue the command “echo $PATH”.
If you were following my instructions above, it should look something like:
/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin
LikeLike
I can’t seem to get Subversion to work. I install it from one of the binaries, but when I go into terminal, it tells me that the command “svn” is not found. Any ideas?
LikeLike
Zach – check your $PATH, as I mention above. With subversion installed through DarwinPorts, you should find it at /opt/local/bin/svn – try entering in the whole path if it’s not working.
If that failed, make sure you actually got it installed:
‘port installed’ will show you all the installed DarwinPorts packages. ‘sudo port install subversion’ is the line that asks DarwinPorts to install subversion and all the needed pieces to make it work.
LikeLike
Oh, well, it was just a bad day. I got it fixed, although not in the way I would prefer. Now I’m back at step 0 and debating trying this again. Perhaps tonight after I’ve had a few at the club isn’t the best idea, but Drunken-Django is my new favorite party game.
As for the problem with my computer – Terminal, running as bash, would read several files to compile a complete path string, but the documentation that exists online talks of .profile or .bash_profile for the most part, although I did find one mention of .bashrc, but it spoke of that file being in the top level /bin. it’s not, it’s and it’s actually not .bashrc, it’s bashrc (no dot) and it’s in the /etc folder, which is a symbolic link to somehwere else.
For someone who sees the command line as a character from TRON, this is bewildering. But I got it fixed…
… end of line.
LikeLike
Gah! I got Subversion to work and installed Django with the sudo python setup.py command, and everything goes fine, but when I try the ‘django-admin.py” command I get the ‘command not found’ message. What did I miss?
LikeLike
Aside from being a much more in-depth darwin-ports install, I did the same thing. However, and I have no idea what I might have done wrong, I now I’m experiencing issues with Django and get a “command not found” when entering “django-admin.py”.
I haven’t had time to really address this issue, but my path is set up correctly, and can access the admin page for the “mysite” tutorial. Normally, I’m not this dense .. well, okay, that’s debatable, but I’ve really tried!
Hopefully in August I’ll get back to testing it out again.
LikeLike
There should be either a copy or a link to django-admin.py at /opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin/.
First, check to make sure that directory is showing up in your path. Easiest way to do that is to use the command “echo $PATH” – and the results of what you should expect to see are detailed earlier in the comments.
Assuming that’s good, change to that directory and make sure the command is there, listed, and executable:
cd /opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin/
ls -al
and you should see something akin to:
drwxr-xr-x 10 root admin 340 Jun 24 00:05 .
drwxr-xr-x 9 root admin 306 Jun 11 00:57 ..
-rwxr-xr-x 1 root admin 191 Jun 11 15:24 django-admin.py
and maybe some more directories. The setup tools should be dropping it in place, but you can always force a symbolic link as he describes at the end of the article in Have You Ever Kissed a Snake? – another darwinports based installation document.
LikeLike
Hrm. I can’t seem to get Python 2.4 installed. 😦 If anyone has any clue why I’d get this, let me know!
---> Building python24 with target all
Error: Target com.apple.build returned: shell command "cd "/opt/local/var/db/dports/build/_opt_local_var_db_dports_sources_rsync.rsync.darwinports.org_dpupdate_dports_lang_python24/work/Python-2.4.3" && make all" returned error 2
Command output: /usr/bin/install -c -d -m 755 Python.framework/Versions/2.4
libtool -o Python.framework/Versions/2.4/Python -dynamic libpython2.4.a
-lSystem -lSystemStubs -arch_only i386 -install_name /opt/local/Library/Frameworks/Python.framework/Versions/2.4/Python -compatibility_version 2.4 -current_version 2.4
libtool: no library created (no object files in input files)
make: *** [Python.framework/Versions/2.4/Python] Error 1
Error: /opt/local/bin/port: Status 1 encountered during processing.
iMac-Intel:~ jcroft$ sudo port install python24
---> Building python24 with target all
Error: Target com.apple.build returned: shell command "cd "/opt/local/var/db/dports/build/_opt_local_var_db_dports_sources_rsync.rsync.darwinports.org_dpupdate_dports_lang_python24/work/Python-2.4.3" && make all" returned error 2
Command output: /usr/bin/install -c -d -m 755 Python.framework/Versions/2.4
libtool -o Python.framework/Versions/2.4/Python -dynamic libpython2.4.a
-lSystem -lSystemStubs -arch_only i386 -install_name /opt/local/Library/Frameworks/Python.framework/Versions/2.4/Python -compatibility_version 2.4 -current_version 2.4
libtool: no library created (no object files in input files)
make: *** [Python.framework/Versions/2.4/Python] Error 1
Error: /opt/local/bin/port: Status 1 encountered during processing.
LikeLike
Joe,
I’ll definately go thru what you’d suggested … some of which I already had, but you’ve given me a bit more to look at. Thanks so much!
Jeff,
if Joe can’t help, I know that the DarwinPorts mailing list really helped me out when I had an error I didn’t quite understand. When I did just the “sudo port install python24” in my setup, I didn’t have a problem … but I didn’t do what joe did, with “sudo port install sqlite3 py-sqlite python24”.
LikeLike
Nice article. Wish I had seen this before I slogged through everything on my own.
One question: how do I get mod_python installed into the local Apache environment?
LikeLike
Hey Jeff, I wrote you off-line because I thought that might be more efficient than blog comment.
Nephilim – if you’re using DarwinPorts (as above), then I’d recomment using Apache 2.x with mod python from the ports tree. There’s a lot more config than can quickly go into a comments – but the core of getting it installed is:
sudo port install mod_python apache2
That will drive a number of dependencies to be built along with the core – but it’ll get it all set up and installed.
LikeLike
w00t!
Got it on the second run, so it’s probably a result of my drinking problem. The first time I didn’t have my good friend Mr. Walker with me, and Johnny and Django they are quite a pair.
All kidding aside, I do find it odd that I’m able to get through complex things when just in from a night out at a bar (cheap bar at that) with friends (cheap friends, too! but I love ’em) imbibing an ocean of booze.
and now, to go do another app! Thanks for all the help guys, it’s been and will continue to be most appreciated.
LikeLike
What am I doing wrong?
This is whats in:/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin/
drwxr-xr-x 7 root admin 238 Jul 27 12:00 .
drwxr-xr-x 9 root admin 306 Jul 27 12:00 ..
-rwxr-xr-x 2 root admin 145 Jul 26 23:44 idle
-rwxr-xr-x 2 root admin 130 Jul 26 23:44 pydoc
-rwxr-xr-x 2 root admin 17528 Jul 26 23:44 python
-rwxr-xr-x 2 root admin 17528 Jul 26 23:44 python2.4
-rwxr-xr-x 2 root admin 18066 Jul 26 23:44 smtpd.py
thanks -m
LikeLike
Hey matt,
Not sure what went south, but try this:
1) verify that django is there somewhere… If you followed my directions, then you should find a copy of django-admin.py at /opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages
(ls -l /opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages)
If it’s not there, you may have run the “python setup.py install” step with Mac’s default python, not the new python24 that is installed from DarwinPorts. The command “which python” should return:
/opt/local/bin/python
If it doesn’t, then check your PATH environment variable, and stick /opt.. bits prior to the rest of yoru $PATH.
What I see in /opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages is:
drwxr-xr-x 7 root admin 238 Jun 11 15:24 .
drwxr-xr-x 586 root admin 19924 Jun 11 00:57 ..
drwxr-xr-x 4 root admin 136 Jun 11 15:24 Django-0.91-py2.4.egg
-rw-r–r– 2 root admin 119 Jun 11 00:55 README
-rw-r–r– 1 root admin 225 Jun 11 15:24 easy-install.pth
drwxr-xr-x 10 root admin 340 Jun 11 15:23 setuptools-0.6a9-py2.4.egg
-rw-r–r– 1 root admin 115 Jun 11 15:23 setuptools.pth
If you don’t see any of that there, your “sudo python setup.py install” command didn’t complete or had problems for some reason.
LikeLike
Yeah… it exists in:
/System/Library/Frameworks/Python.framework/Versions/2.3/bin
drwxr-xr-x 9 root wheel 306 Jul 27 11:24 .
drwxr-xr-x 10 root wheel 340 Jul 1 18:27 ..
-rwxr-xr-x 1 root wheel 185 Jul 27 12:37 django-admin.py
-rwxr-xr-x 1 root wheel 280 Jul 27 11:24 easy_install
-rwxr-xr-x 1 root wheel 288 Jul 27 11:24 easy_install-2.3
-rwxr-xr-x 1 root wheel 111 Mar 20 2005 idle
-rwxr-xr-x 1 root wheel 44 Mar 20 2005 pydoc
-rwxr-xr-x 1 root wheel 13752 Mar 20 2005 python
-rwxr-xr-x 1 root wheel 13752 Mar 20 2005 python2.3
The only thing in: /opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages
is README
-m
LikeLike
Matt: Bingo – change your PATH in .bash_profile or something akin and re-run the installation script, and you should be good.
LikeLike
Thanks Joe… Works great!
-m
LikeLike
@ Thomas M’s “command not found†when entering “django-admin.pyâ€.
It seems to be a permissions issue on Mac. See the comments at http://www.djangoproject.com/documentation/install/ – it says chmod 644 on your django/bin directory will fix the issue, but shamefully I had to use 777 to get the thing working.
LikeLike
if only i could get django running it would be a great platform for (local) backoffice handling.
isn’t there a nice and simple (double clickable) install package for both osx (10.3 / 10.4) and XP which takes care of everything?
my clients will get lost in too many steps…
LikeLike
Sorry Floris,
No one-click install for any platform.
LikeLike
I seem to be having a similar problem to Kevin, although I may be even more inexperienced with setting up my PATH and all. I downloaded and installed DarwinPorts (actually a later version) and it wouldn’t recognize the “port” command. Even after trying to alter ~/.profile it didn’t do anything.
This seemed like it would be the easiest solution (next to that non-existent one-click install), and hopefully this is only an initial roadblock. (Also, I’m not sure if you were thinking about updating the link in the article for the new site for DarwinPorts, or if you were planning on updating the article for the 0.95 release. Just a thought.)
LikeLike
Attempting to get this mf to work with OS X 10.4 has resulted in one of the most hideous evenings of my entire life. You know — one of those evenings where you keep throwing good time after bad because you’ve already sacrificed so much, you just can’t give up and go to bed. Well, I’m done.
Onward to Turbogears, or Rails.
LikeLike
Sorry it didn’t work out for you. Hopefully we’ll have a better installation setup before too long.
LikeLike
If i wanted to also use my existing mysql5 local server, does anyone know what i would have to do?
This tutorial has been excellent by the way!
Jason
LikeLike
Jason,
Following on the MacPorts setup, you just need to add the MySQL server and the associated python database adapter. I haven’t tried this recently, but the following should do the trick:
sudo port install mysql5 py-mysql
There’s more to be done regarding setting up MySQL, but that’s really best left to a more detailed description on MySQL specifically.
LikeLike
I got to the same place as Matt above… and was able to load everything and make it work, except ‘django-admin.py’ which returned ‘command not found’.
Here’s some more that may help for trouble-shooting my problem:
Here’s the actual text:
david-ferrells-power-mac-g5:~/django-trunk dwf$ django-admin.py
-bash: django-admin.py: command not found
echo $PATH spit out the following:
/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
I’m using the base Tiger install of python2.3, and I don’t know how to upgrade to python2.4 (I’m not a Terminal guru, so any advice will be welcome)
I’m able to see all files at /usr/lib/python2.3/site-packages/django
I installed Port Authority but I don’t understand how this helped me, if at all. I didn’t use the GUI for Port Authority… I just walked through these commands verbatim and it worked:
sudo port -d selfupdate
sudo port install subversion
sudo port install sqlite3 py-sqlite python24
sudo port install py-docutils py-mx
Help?
David
LikeLike
By the way, I also tried entering that command in python, and it rewarded me with the following lovenote:
david-ferrells-power-mac-g5:~/django-trunk dwf python
Python 2.3.5 (#1, Oct 5 2005, 11:07:27)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> django-admin.py
Traceback (most recent call last):
File “”, line 1, in ?
NameError: name ‘django’ is not defined
LikeLike
David,
The key here is installing and using the DarwinPorts. Port Authority will help, but there’s some underlying things you need to catch onto to make it all work.
First, there’s the path. When you’re using ports, you want to change how the computer finds programs- so you update the PATH environment variable to do that. It’s detailed in the DarwinPorts install.
I’m going to guess that if you followed my directions exactly, and they worked, that Django is ready to go using Python 2.4, but you invoked python 2.3.5 (the base installed with the Mac).
Check out the instructions at http://darwinports.opendarwin.org/docs/ch01s03.html for updating your PATH. When you type “python” on the command line at a terminal, it should tell you that it’s running python 2.4.something and “import django” shouldn’t return any errors.
LikeLike
Sorry to jump in so late, folks.
Joe — I believe I’m hitting the exact same problem that Jeff was having above, but while trying to install sqlite3 (“sudo port install sqlite3” –> “Error: Target com.apple.build returned: shell command”…blah blah…”Error: Status 1 encountered during processing.” Would you mind passing on whatever helpful advice you gave to him?
Thanks!
LikeLike
Sorry to be really, really late… but I am having a similar problem to Jeff with the python24, only my error is as follows:
$ sudo port install python24
—> Building python24 with target all
Error: Target com.apple.build returned: shell command “cd “/opt/local/var/db/dports/build/_opt_local_var_db_dports_sources_rsync.rsync.darwinports.org_dpupdate_dports_lang_python24/work/Python-2.4.3″ && make all” returned error 2
Command output: /usr/bin/g++-4.0 -u _PyMac_Error Python.framework/Versions/2.4/Python -o python.exe
Modules/ccpython.o
-ldl
/usr/bin/ld: can’t locate file for: -lgcc_s.10.4
collect2: ld returned 1 exit status
make: *** [python.exe] Error 1
Error: Status 1 encountered during processing.
if anyone has any suggestions, they would be greatly appreciated! Thanks
LikeLike
PS.. i’m on a core 2 duo macbook pro
LikeLike
May be too late, but I’m having the same problem as Chris, Gabe, and Jeff, but only when installing python2.4. btw, I can install python2.3 from MacPorts without a problem, but 2.4 returns an error identical to the one Gabe posted. I’m also on an Intel MacBook. I’d appreciate any help. THanks.
-Matt
LikeLike
Oh my. What a mess.
There is really no need to mess with Darwinports. Python 2.3 and sqlite come already with MacOSX. You might want to install the official Python 2.5 (from python.org) though, because it includes already the sqlite3 module.
Then just follow the installation instructions on the Django web site.
LikeLike