I recently installed a full development environment for Django on Windows 7 and found that it took longer than expected. The path to getting everything working together wasn’t immediately apparent. I made a few missteps along the way and hopefully this post will make it a bit easier for the next developer.
The tools that I installed are:
- Python 2.7
- pip 0.8.2
- Postgres 9.0
- Django 1.3 Beta 1
- Intellij IDEA 10
Python
Just go to the Python download page and pick the version for you. I installed Python to C:\dev\tools\python27. Then I added C:\dev\tools\python27\Scripts and C:\dev\tools\python27 to my system PATH environment variable.
pip
To me it appears as though packaging in Python is in a painful disarray/flux. As far as I can tell pip is the way to go for Python 2.x. After reading What’s the proper way to install pip, virtualenv, and distribute for Python? I did the following to get pip installed.
- Download http://python-distribute.org/distribute_setup.py to C:\dev\temp
- Ran command: cd C:\dev\temp
- Ran command: python distribute_setup.py
- Ran command: easy_install pip
Now that pip is installed we can:
- Install packages: pip install SomePackage
- Uninstall packages: pip uninstall SomePackage
- Upgrade packages: pip install –upgrade SomePackage Plus a whole lot more. For me, the above is already enough to choose pip over easy_install.
Postgres
Go to the Postgres download page and install it.
Now you’ll need a python-postgres database interface library. For this we’ll use psycopg. Go to the win-psycopg download page and pick the version that most closely matches your Windows/Python/Postgres versions.
Note that when you start a Django project you’ll want to use django.db.backends.postgresql_psycopg2 for your database ENGINE value in your settings.py.
Django
I wanted to take the latest beta release of Django for a spin so I didn’t install it via pip. However, when Django 1.3 is released on January 31, 2011 I’ll definitely be installing it with pip. Instead I more or less followed the Quick install guide for Installing an official release:
- Went to the Django download page and grabbed the latest tar.gz
- Extracted it to C:\dev\temp with 7-Zip
- Ran command: cd C:\dev\temp\Django-NNN
- Ran command: python setup.py install
After that’s done you’ll want to verify your install and try the tutorial.
While going through the tutorial I found that django-admin.py startproject mysite [was] not working well on windows 7. That’s already been reported to the django project, see http://bugs.python.org/issue7936. Here’s a solution:
- Open regedit
- Find python.exe (for instance, under HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command)
- Change “C:\dev\tools\python27\python.exe” “%1” to “C:\dev\tools\python27\python.exe” “%1” %*
I also stumbled onto a bug in Django on Windows, Cannot load admin interface static files when doing tutorial. Painful but something that should be fixed in the next beta release.
Intellij IDEA
Intellij IDEA has great support for Python and Django development. If you’re strictly doing Python development you could just download PyCharm. However, I already had IDEA 10 already installed so I just added the Python plugin (essentially PyCharm) from File > Settings > Plugins.
To get IDEA working with an existing Django project (for instance, the Django tutorial) you have to jump through a few hoops. I followed the instructions from Using Intellij for Django Development.
Conclusion
It’s a lot to do and a lot to configure but in the end it’s worth it. Python/Django development is fast, effective and the end result can be some easily maintainable code.