Thursday, October 20, 2011

Setting up a Django Environment (Eclipse, MongoDB, MySQL, Python)

I will be going over some of the steps to set up a Django development environmental.  Django is a popular Python Web framework that encourages rapid development, it is well documented and there are plenty of experience users if one runs into trouble.
Note: I'm setting all these packages in a Windows environment.


Installing Python
1.  Get the Python binaries from here.  
2.  If you get the installer, the installation becomes quite easy - simply, click and agree. 
     I put my installation in the root directory ("C:\Python27") but you can put it anywhere.
3.  To test the installation,
     Open the command prompt and type: python. If there are no errors you should get something 
     like this ">>>" at the beginning of the line. This means that the Python interactive 
     interpreter is ready go. 
     If you don't see this, you might have to add Python to the system variables PATH.  
     There are several ways to get there. One is to go Start->run and type sysdm.cpl, after that 
     select Advance tab, click Environment Variables and under System Variables add the
     following to the path: C:\Python27;C:\Python27\Tools\Scripts
Installing Django 
1.  Get the packages from here.
2.  Extract the folder.
     Open a command prompt, navigate to this folder and type: python setup.py install. 
     This will install all the required files in the site-packages directory. In my system this is 
      in "C:\Python27\Lib\site-packages\django"
      To tell if Django is installed open a command prompt and type python to run the
      Python interactive interpreter (>>>) type import django. If no errors are shown, 
      then Django is installed.
 Installing PyDev Plugin
1.  I like working with Eclipse IDE for my Java projects. And I am glad I can still use it with 
     my Python projects. With Eclipse open go to Help->Install New Software-> 
     Work with ("add the following from link from here") -> select PyDev and install it.
     This is all we need to start with Django and Python in Eclipse.


Extras - I'm using the following databases so I'll add the installation instructions for these two as well.
MongoDB
1.  Get MongoDB from here
2.  Download and unzip the file. I put the extracted folder at the root (“C:\mongodb-2.x”) .
3.  Next, we have to create the data directories were MongoDB will store the data.
     The default locations is in "C:\data\db" you can create these directories via the Windows
     Explorer or through the command prompt by navigating to the "C:\" drive, create a data 
     folder (mkdir data), cd to this created folder and create an new folder (mkdir db).
4.  To test the installation open a command prompt and navigate to the ("C:\mongodb-2.x\bin").
5.  To run the   database server execute the "mongod.exe". To run the administrative shell 
     execute the "mongo.exe" .
Python driver for MongoDB
1.  The driver needed to work with MongoDB is pymongo you can get it from here.
2.  Install the downloaded binaries.
3.  To test the installation go to a command prompt and type python to get the Python 
     interactive interpreter.  Type import pymongo.  If no errors are shown the pymongo 
     module was installed correctly. 
4.  Try connecting to the MongoDB by typing the following code: 
     connection  = pymongo.Connection("localhost", 27017) 
     The port number is the default port number used by MongoDB.
MongoEngine 
1.  This installation is really very much optional, since most DOM (ORM) solutions are very new.
     However, I'm going to experiment with MongoEngine which is a Document-Object Mapper 
     (very similar to Django's ORM)
2.  Get zip file and extract the files  here.
3.  Open a command prompt navigate to the root of the folder extracted and type:
     python setup.py install
4.  The first time I tried installing it I got an exception about the "setuptools" missing.
5.  Get the setuptools installer from here
6.  Installed them and try step 3 again.   
MySQL
1.  Get the installer from here.
2.  Install the downloaded binaries. The installation it is pretty easy just click next and 
     agree to term and conditions :)
3.  A MySQL command line client should available be under the MySQL installation 
     directory.
MySQL Python driver/adapter
1.  Get the adapter binaries from here.
2.  Install the adapter by executing the binaries.
3.  The best way to test this is to create a database in MySQL and a Django project.


That is it, we should be ready to start writing some Django apps.

5 comments:

  1. And where is the setup with eclipse? :3

    ReplyDelete
  2. Hi Maximino, Please reach out to me.
    I cant post too much out here but i'm hppy to speak with you.

    BR Jerry Jimenez C# 214 859 0141 off#469.608.6933
    Robert Half - BIG DATA

    ReplyDelete
  3. Hi Maximino, Please reach out to me.
    I cant post too much out here but i'm hppy to speak with you.

    BR Jerry Jimenez C# 214 859 0141 off#469.608.6933
    Robert Half - BIG DATA

    ReplyDelete