Thursday, June 21, 2012

One stop guide: Get MySQL running on Ubuntu!!

This tutorial explains the process pretty well. Also highlighted in it are the errors I faced during the process..
$ sudo apt-get install python-dev libmysqlclient-dev
$ pip install MySQL-python

This should let you run the staging database.

For your local mysql databses,
$ sudo apt-get install mysql-server

mysql -u root -p
>enter password

mysql> CREATE USER 'efldbadmin'@'localhost' IDENTIFIED BY 'some_pass';


Import sql file into the db:

mysql -u efldbadmin -p stg_mullet < mullet_2012-05-25.sql
Enter password:


Wednesday, June 13, 2012

Quick guide to setting up virtualenv

UPDATE: I just learned about virtualenv-burrito which installs virtualenv along with virtualenvwrapper which provides neat wrapper functions to work smoothly with virtualenv.

So here's how you go about installing virtualenv burrito:

If you do not already have curl installed:
$ sudo apt-get install curl

Next, follow these simple instructions:
$ sudo curl -s | $SHELL

And when you're done do..
$ source /home/<<username>>/.venvburrito/  [You will have to run this command each time you start a new terminal]
Replace <<username>> with your relevant username..

Now to make your first virtualenv,
$ mkvirtualenv <<name>>

to use it..
$ workon <<name>>

The directories for this virtualenv are available at

to quit a virtual env
$ deactivate

Here's a good guide on the same:
1. $ sudo easy_install virtualenv
2. Navigate to/create a folder where you want to store your virtual environment project.
3. $ virtualenv --no-site-packages projectname
You're done.
To start using your venv..
4. $ cd projectname
5. $ source bin/activate
6. Install dependencies from requirements.txt using this tutorial. Note: You do not need mysql. [Here's a requirements.txt dated 06/13/2012 to use.]
7. To quit..  $ deactivate
8. Make sure you use easy_install to install packages as opposed to pip because I noticed that pip does not always install to the venv directory, rather it goes to the usr/local/lib/ directory.

To setup Eclipse to run your django venv
1. Change Eclipse's Python interpreter by..
- Eclipse > Window > Preferences > Interpreter - Python > New...
- Navigate to /path/to/venv/projectname/bin/python . Hit OK.
- Scroll down and make sure you also check the following folders (which may be unchecked) at the "Selection needed" screen..
These may be named differently on your system. If you do not check these and if you get an error "Python stdlib not found...." make sure you DO check these folders too!
2. Remove any other interpreters just in case.
3. Hit Apply. Then Hit Ok.
4. Inside the Debug Configuration just make sure that the Interpreter is pointing to the new interpreter you just created.


Setting up Eclipse Debug configs to work with Django

  • Eclipse > File > Import > General > Existing projects into workspace > Next > 
  • For 'Select root directory:' browse to the app folder. [the one with] and hit Finish.
  • We now need to install PyDev,
    Help > Install New Software > Add...
    Name: Pydev    Location:  >> OK
    Select only PyDev and not PyDev Mylyn... >> Next > Next > I accept > Finish > Trust all certificates > Restart Eclipse when prompted.
  • Eclipse > Debug Configurations > Python run.
  • Right click on Python Run > New.
  • Click the New_configuration which is newly created in the left pane.
  • For Project, Browse to the 'app' folder. [the one with]
  • For Main Module, Browse to the '' inside the above app folder.
  • Then click the Arguments tab at the top.
    Add 'runserver 8000 --noreload' (without quotes) into Program arguments.
  • Hit Apply. You're done.

NOTE: You may also have to select the appropriate Interpreter after selecting Arguments. Use /path/to/venv/projectname/bin/python if inside a venv else use usr/src/bin/python2.7

Gadjo / request-provider

More often than not gadjo does not install using easy_install or pip as easily as the rest of the requirements from requirements.txt.

Best fix..

Download the requestprovider folder from here. or here
Navigate to the "gadgjo" folder.
Paste the gadjo folder into local/lib/python2.7/site-packages  [This was for a virtualenv]
Paste the gadjo folder into usr/lib/python2.7/dist-packages [without virtualenv]


Use requirements.txt to work on virtualenv


Make sure you perform all pip installs WITHOUT sudo to make sure they are isolated to the virtualenv.
Also, manually pip installing each requirement works fine for now.
Will update this with an automated method later..

So it turns out that using pip in a virtualenv actually looks into the /usr/lib/python (ie. the host's directory) for prior installation..

For a fully isolated virutalenv, pip doesn't work right..

easy_install does though..

however easy_install is not compatible with requirements.txt generated by pip...
[Here's a requirements.txt dated 06/12/2012]

so use this script to get it done:

import os

f = open("requirements.txt")
reqs ="\n")

for req in reqs:
    # ignore comments or pip options
    if req.startswith('--') or req.startswith('#'):
    # ignore blank lines
    if len(req) > 0:
        os.system("easy_install %s" % req)

works like a charm..

Popular Posts