Thursday, December 31, 2009

Using django-admin.py within cygwin

Sometimes I still work in windows environment. I always have cygwin installed in windows environment since I use a lot of *nix tools and scripts.
Currently, I am working a lot with python and django, very nice scripting language and powerful web framework. I used native windows python installation, instead of installing it within cygwin.
The problem occur when I tried to invoke django-admin.py script in cygwin's bash shell. It won't run. It is due to windows version of python expecting windows path of the django-admin.py script as the argument.
Here is the exact situation. Windows python expecting, something like this:

python c:\Python26\Scripts\django-admin.py


but since I run that command within cygwin, it will become like the following:

python /cygdrive/c/Python26/Scripts/django-admin.py


and throws some error messages.

So, I searched a bit and found out that cygwin has a tool that converts *nix path to windows path. The name of the tool is cygpath.

And here is what I did to solve the problem.
I created the following file:
/usr/local/bin/django-admin.py

which contains:
python.exe "$(cygpath -aw "/cygdrive/c/Python26/Scripts/django-admin.py")"

Of course you need to make /usr/local/bin/django-admin.py executable

chmod +x /usr/local/bin/django-admin.py


and you can run django-admin.py from anywhere.


Check out the following links for more information:
http://www.cygwin.com/cygwin-ug-net/using-effectively.html
http://www.cygwin.com/cygwin-ug-net/using-utils.html#cygpath

2 comments:

  1. Why Cygwin when one can use linux ?

    ReplyDelete
  2. @viyyer: Nice one! Well, sometimes, in life you could have stranded in a land without Linux and have only Windows. In that case... cygwin is your best friend.

    ReplyDelete