My Python Virtual Env Setup Instructions

Seeing as though I am always building different Ubuntu virtual machines to perform various python actions on (often on different customer sites), I find myself setting up the same things over and over again.

My notes for this process are normally scattered between Notepad/TextEdit and Evernote, so its about time to put them all in the one spot so I can reference them easily.

Depending on the environment I am working in, I may need to do an upgrade of the Ubuntu OS.

Once the VM has been upgraded and rebooted, lets update APT.

Now install git & git-flow

Install PIP if it is not already installed

If PIP is already installed, maybe update ip

Install virtualenv via PIP

Create a directory which will store the virtual environments

It is at this point that it is possible to be able to use the virtual environments now, but its a bit tedious, so we install virtualenvwrapper to make things easier.

Edit the ~/.bashrc file and add this to the bottom of the file

Exit and re-open you shell, or reload the ~/.bashrc file with the following command and you will be ready to start using virtualenvs and virtualenvwrapper.

Working with VirtualEnvs


Creating a new virtualenv

Delete a virtualenv

Show all virtualenvs configured

Use either of the following 2 commands to list all the virtualenvs configured

Use a particular virtualenv

Stop using a virtualenv

Using PIP

Show all python packages installed within the virtualenv

To generate a list of modules that need to be installed to replicate the current environment use the following command

And you can also save this to a file which can then be used later to install all the modules in another environment via PIP








Leave a Reply