Friday, January 31, 2014

Django Setup for Windows

I know that most Django developers are using Linux and such operating systems, but some of us have no choice but to use windows. And it actually works! Even in production! (although not the ideal choice...)

I've been working with Django for several years now (I used to develop mainly in Java/Spring/Hibernate etc.), and at first I was very skeptic, but now - I'm planning to start my new venture with Django/Python as well.

So, if you have to use a windows environment, here are the first steps to setup you env:

  1. Install Python
    Install python 2.7 (you can also use python 3, but it's different...and I'm not writing about this here) from http://www.python.org/download/
    Setup python 2.7 in your windows environment variables (if you do not know how to set the environment variables view http://www.itechtalk.com/thread3595.html).
  2. Database installation
    Install the database you want (MySQL, PostgreSQL etc. even SQLServer will work, but this is not a natural choice).
  3. Install the Database Driver
    For each database you chose, you should download the relevant driver for python, for example, MySQL driver can be found here - http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download, there's a windows installation available in codegood.com (I used this installation for my windows env).
  4. Install Pip
    So what is pip? Pip is the python package index, it will make your life easier! by using a simple command -
    pip install <your_package>
    you'll be able to install almost any python package available.
    To install pip, first download "easy install" from https://pypi.python.org/pypi/setuptools/2.1#windows
    Now, from the command line write
    easy_install pip 
    And you are ready with pip.
    To see the available packages that can be installed with pip see - https://pypi.python.org/pypi
  5. Install VirtualEnv (in a nutshell...)
    I'm not going to exaplin about the virtual anv here, but basically if you want to run several applications with several Django versions etc. You should use the virtual env, which stores in a local folder all the packages relevant to your app.
    To install -
    easy_install virtualenv
    Or
    python pip install virtualenv 
    See http://www.virtualenv.org/en/latest/virtualenv.html

  6. Eclipse setup with PyDev
    It's not mandatory, but it will make your life easier when coding.
    Download eclipse from http://www.eclipse.org/downloads/
    Install PyDev from eclipse "Help" --> "Install New Software" --> In the "work with" section add PyDev - http://pydev.org/updates

  7. Install Django
    From the command line run
    pip install django==1.6.1   
    (1.6.1 is currently the latest official version).
    If you are using a virtual env, make sure you run pip from within the relevant application.
  8. Start the Django Tutorial 
    https://docs.djangoproject.com/en/1.6/
    I recommend to start developing with eclipse.
I'm here if you have any questions,
good luck.




3 comments: