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.

1 comment:

Popular Posts