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.. http://codeinthehole.com/writing/how-to-set-up-mysql-for-python-on-ubuntu/
$ 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

Then..
mysql -u root -p
>enter password

mysql> CREATE USER 'efldbadmin'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'efldbadmin'@'%' WITH GRANT OPTION;

CREATE DATABASE stg_mullet;

Import sql file into the db:


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

DONE!

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: https://github.com/brainsik/virtualenv-burrito
$ sudo curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL

And when you're done do..
$ source /home/<<username>>/.venvburrito/startup.sh  [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
/home/<<username>>/.virtualenvs/<<name>>

to quit a virtual env
$ deactivate


#Deprecated
Here's a good guide on the same: http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
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..
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux
/usr/lib/python2.7/lib-tk
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.

Done.

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 manage.py] and hit Finish.
  • We now need to install PyDev,
    Help > Install New Software > Add...
    Name: Pydev    Location: http://pydev.org/updates  >> 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 manage.py]
  • For Main Module, Browse to the 'manage.py' 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 http://pypi.bearstech.com/django-contrib-requestprovider/
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]

Done.

Use requirements.txt to work on virtualenv

EDIT:

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..

#DEPRECATED
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:
http://metak4ml.blogspot.com/2009/08/easyinstall-read-pip-requirementstxt.html

import os

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

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


works like a charm..

Popular Posts