Richard Jones' Log

Mon, 20 Jan 2014
Python 3.3 and virtualenv

We're kicking off some new projects using Python 3 (yay!) but had some issues getting virtualenvs working. Which is kinda ironic given that Python 3.3 included virtualenv in it, as pyvenv. Unfortunately, pyvenv isn't quite the same thing as virtualenv, and in particular it doesn't install/include pip and setuptools. There's also some additional issues introduced under Ubuntu.

First, you'll need to obtain Python 3.3. Some of the methods you could use will work and some are known to produce a non-viable environment. In particular:

  • OS X: get it from homebrew ("brew install python3"). I've not tried other avenues, but this works and is the easiest approach in my opinion.
  • Ubuntu: get it from source, building like so:
    sudo apt-get install build-essential libsqlite-dev sqlite3 bzip2 libbz2-dev
    tar jxf ./Python-3.3.3.tar.bz2
    cd ./Python-3.3.3
    ./configure --prefix=/opt/python3.3
    make && sudo make install
    Do not attempt to use any currently-available pre-built packages (eg. from a PPA) as they will create broken virtualenvs. See this discussion for some enlightenment, but note the lack of a reasonable solution.
  • Windows: no idea, sorry.

Now that you've got a Python 3.3 installation, you can create your virtual environment. You do this with this command combination:

. /bin/activate

Now you should have a viable, working Python 3.3 virtual environment.

Fortunately Python 3.4 is going to improve on this by installing pip alongside python.

Also, pip 1.5.1's "" will let you skip that extra setuptools install above when it's out (real soon).

category: Python | permanent link