Virtualenv ubuntu

As of Python 3.3 virtual environments have been supported from within the language See the PEP: Previously to get a virtual environment you would typically use virtualenvwrapper.

An annoyance I ran into is that the virtual environment that shipped with some versions of Ubuntu and debian is broken. Specifcally I found that Ubuntu 14.04 was broken when I tried to use it:

pyvenv-3.4 ~/my_venv
Error: Command '['/home/cg/my_venv/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

If interested you can see the bug report here: Now you can somewhat work around the issue by not using pip with the --without-pip option. But given the usefulness of pip that seems like a poor "solution" overall, especially considering the ease of updating. Luckily this isn't too difficult to fix:

sudo pip install --upgrade virtualenv

Now we should be able to create our virtualenv's if this upgrade succeeds.

virtualenv-3.4 --python=python3.4 my_env

This will create a directory called my_env that contains the virtualenvironment. Within this is the activation script.

source ./my_env/bin/activate

If this has succeeded then your command prompt should change to reflect this with a prefix of (my_env)). Test that this has sucessfully set up the install by doing which python, if this points to the Python in the virtual environment directory all has gone well. Now if you install things with pip they will install into this virtual env. Now I personally like to keep a requirements.txt file that contains all the packages installed by pip:

pip freeze > requirements.txt

This should be all you need to do!