How to install pip, virtualenv and django on ubuntu

Published December 22, 2011 by Toran Billups

I recently started developing on linux again, but this time I'm doing Python professionally. And with any new platform, you learn how to setup your development machine on day one. Initially I just installed Python 2.x and started writing code without a care in the world. But it turns out most of the real-world Python developers are working with this thing called virtualenv.

The short version -virtualenv allows you to silo a development python environment from system Python. So without further ado -the steps below will get you up and running from a fresh install of Ubuntu 11.10

This install assumes you are a normal (non root) user who has sudo access to install packages (but please don't do something like sudo -i before starting this install)

sudo apt-get update

sudo apt-get install python-setuptools python-dev build-essential git-core -y

sudo easy_install pip

sudo pip install virtualenv

sudo pip install virtualenvwrapper

At this step type pwd **to make sure this is your home dir -ie /home/toranb. If you are not cd ~/ and you should be.

mkdir ~/virtualenvs

echo 'export WORKON_HOME=~/virtualenvs' >> ~/.bashrc

echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bashrc

echo 'export PIP_VIRTUALENV_BASE=~/virtualenvs' >> ~/.bashrc

source ~/.bashrc

The above is a great start, but if you want to use the best Python editor known to man keep going. If you don't want a bulky IDE or you just don't have the hardware to run it, install vim the right way as the vanilla install of ubuntu won't have anything installed.

sudo apt-get install vim vim-scripts vim-doc vim-latexsuite vim-gui-common vim-gnome -y

If you decided to install the Pycharm editor -it requires the JDK so let's get started!

sudo apt-get install openjdk-7-jdk -y

Next go download Pycharm from jetbrains. Once this is finished cd into your downloads directory

cd ~/Downloads/

tar xvzf [name of the tar.gz]

Now cd into that new directory after the extraction is finished.

cd bin

./pycharm.sh

Now you have a full python stack so lets create our first virtualenv and install django! (back to the terminal)

mkvirtualenv blog

This will create a new virtualenv (very minimal install). To install django use pip.

pip install django

Now you can develop, install other packages using pip,etc (go to town people!)

If you want to get out/off your virtualenv use this command

deactivate

If you want to jump back on the virtualenv we just created and installed django use this command

workon blog

And finally if you want to remove the virtualenv altogether

rmvirtualenv blog

Now you should have a fully functional Python/Pip/Virtualenv/Django development environment!


Buy Me a Coffee

Twitter / Github / Email