Thursday 22 May 2014

Creating Virtualenv for Django project.

Install distribute and pip

curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
sudo easy_install pip
 
pip completion --bash >> ~/.bashrc

and run source ~/.bashrc to enable

Use pip to install virtualenv and virtualenvwrapper

sudo pip install virtualenv
sudo pip install virtualenvwrapper
 
export WORKON_HOME=`~/.virtualenvs`
 
mkdir $WORKON_HOME
 
echo "export WORKON_HOME=$WORKON_HOME" >> ~/.bashrc
 
Setup virtualenvwrapper
 
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
echo "export PIP_VIRTUALENV_BASE=$WORKON_HOME" >> ~/.bashrc       

Source ~/.bashrc to load the changes

source ~/.bashrc

Test if it works

Now we create our first virtual environment
 
mkvirtualenv test

You will see that the environment will be set up, and your prompt now includes the name of your active environment in parentheses. Also if you now run
 
python -c "import sys; print sys.path"

you should see a lot of /home/user/.virtualenv/... because it now doesn't use your system site-packages.

You can deactivate your environment by running
 
deactivate

and if you want to work on it again, simply type
 
workon test

Finally, if you want to delete your environment, type
 
rmvirtualenv test
 
 
To Install Django  

$ pip install django
$ which django-admin.py
$ django-admin.py startproject django_project
 
ENJOY!!!!!! 

No comments:

Post a Comment