Thursday, 22 May 2014

Creating Virtualenv for Django project.

Install distribute and pip

curl -O
sudo python
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`
echo "export WORKON_HOME=$WORKON_HOME" >> ~/.bashrc
Setup virtualenvwrapper
echo "source /usr/local/bin/" >> ~/.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

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
$ startproject django_project

No comments:

Post a Comment