Setting up django using virtualenv

Still I remember, once I was crying(!) to people to teach me virtualenv 😛 It’s actually I didn’t know that what it does, how it does and what are the benefits of using virtualenv.

Anyway, there are few and very important benefits of using virtualenv. This fantastic tool gives theh power of creating isolated Python environment. Keeps the headache of permission, version of the applications, dependencies etc.

The funnies thing about virtualenv is that, it is enormously easy to setup. YES, I mean it 🙂

sudo easy_install virtualenv

Now go to the directory where you want to create the project and type

virtualenv --no-site-packages vdjango

now install django

./vdjango/bin/easy_install django

Start a django project

./vdjango/bin/django-admin.py startproject myapp

now to the project directory and run the project.

../vdjango/bin/python manage.py runserver 0.0.0.0:8000

tada!!!!

virtualenv – EnvironmentError: mysql_config not found

So I was setting up virtualenv, during the setup process I was having this very common(!) error when I was trying to install MySQL-python. The solution is bit tricky. Though I found solution like, setting PATH on .profile, but actually that might work for normal installation.

I am on Mac OS 10.6.8 and for me the mysql_config file was in /usr/local/mysql/bin/ directory.

Edit the /bin/activate file from the virtualenv directory and add the following lines,

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
PATH="$PATH:/usr/local/mysql/bin/"
export PATH

then run the following command

source virtualenvDirectory/bin/activate

this will change your path to virtualenv’s bin directory.

now try to install MySQL-python again.

and to undo the changes to $PATH

deactivate virtualenvDirectory/bin/activate

and tada!!!