Thursday, December 31, 2009

Using 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 script in cygwin's bash shell. It won't run. It is due to windows version of python expecting windows path of the script as the argument.
Here is the exact situation. Windows python expecting, something like this:

python c:\Python26\Scripts\

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

python /cygdrive/c/Python26/Scripts/

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:

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

Of course you need to make /usr/local/bin/ executable

chmod +x /usr/local/bin/

and you can run from anywhere.

Check out the following links for more information:


  1. Why Cygwin when one can use linux ?

  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.