Django and Windows

Django and Windows two things that may not get along each other very well.

I’ve been developing with Django and Windows over three years now and along the road I’ve developed few practical solutions for my team to make developers life a slightly easier.

My environment consists of few key parts: Python, setuptools, pip, virtualenv and TCC/LE.

Python should be obvious. Download and install it be sure to install 32 bit version. 64 bit version works but you will have great deal of troubles with 3rd party libs. I assume for the rest of the guide that you installed Python 2.7 under C:\Python27

After installing Python you should install TCC/LE. TCC/LE in short is replacement for CMD.EXE – a command prompt replacement. It has lot of nice features.

Now create your working directory, for the rest of the guide I assume that C:\django is working directory containing all virtual envs etc.

Under working directory create subdirectory config. In this directory create startup file for TCC/LE called tcstart.btm

@echo off
rem Override system python binding to handle virtualenvironments
set .py;.pyc=python.exe

Now create (copy) TCC/LE shortcut on desktop and rename it appropriately. Open Properties for shortcut and add to Target “C:\django\config\tcstart.btm”. You probably want to set Start in to something useful, like C:\django

First you need to install setuptools, just to make life a simpler:

http://pypi.python.org/pypi/setuptools#downloads

Now open your newly create TCC prompt and type:

c:\python27\scripts\easy_install pip

and then type:

c:\python27\scripts\pip install virtualenv

Now you’re ready to create your first virtualenv.

type:

c:\python27\scripts\virtualenv my-proj-env –no-site-packages

Replace my-proj-env with suitable name for your virtualenv. Now final step is to activate your virtualenv. You have to do thisĀ every time you start TCC (or command) prompt. Activate enviroment with commands:

cd my-proj-env

scripts\activate.batĀ 

No your prompt should be prepended with name of the virtualenv, and should look something like:

(my-proj-env) C:\django\my-virtual-env\

Now you’re inside isolated Python environment and whatever you install using setup.py, pip or easy_install will be installed in this isolated environment. Note that you can’t use prebundled executable setup packages – they will be always installed in global site packages!

Now it’s time to install Django:

pip install django

After a while you should see that Django is downloaded and installed. You can try out command django-admin.py

If you got list of commands supported by django-admin – congratulations. You have very isolated working environment for your project.

About these ads

3 comments on “Django and Windows

    • I suppose. At least according to Microsoft cmd.exe help page you could have something like “cmd.exe /d /k path/to/config.bat”

      Though since writing this I’ve moved to *nix environment – it just made everything easier.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s