After reading this fine summary of the history of Python 3 by Nick Coghlan I was inspired to update as many of my half finished projects and miscellaneous scripts as possible. Then I looked up and I had lost several hours of my life. To save random internet strangers from the same pain as I experienced here is a catalogue of problems and how I solved them.
tl;dr - Python 3.3 on Ubuntu 12.04 LTS is possible but quite tricky. Unless you like system administration you are probably better off waiting until 14.04 LTS comes out in a few months.
I've settled on a default 'stack' of Python and related technologies that I use for most of the code that I write these days;
- lxml for XML manipulation
- Flask for web development
- PostgreSQL and psycopg2
- Elementary OS as my desktop o/s
The good news is that all of the Python related components of these technologies have been ported to Python 3. The bad news is that Flask only runs on Python 3.3. Elementary OS is based on Ubuntu 12.04 LTS and that only has Python 3.2 in it's repositories.
So, first things first, how do we get Python 3.3 on Elementary OS? Or Ubuntu 12.04 which are interchangeable for the purposes of the rest of this post. Quite easily thanks to the 'deadsnakes PPA' as explained in this askubuntu post.
I also don't like to pollute my system Python or operating system packages with project specific Python modules so I always use virtualenv. Unfortunately this doesn't work with the Python 3.3 acquired from the deadsnakes PPA as that doesn't ship with easy_install.
So by this stage I have Python 3.3 running but no way to create or manage a virtual environment. I then remembered Nick's talk at PyCon AU where he mentioned that a new lightweight virtual environment would be included in the standard library. Sure enough the venv module (and pyvenv script) were present on my system so I decided it was a good idea to use them.
The bad part for me is that (and it says this in the documentation) venv does not include any means of installing other Python packages. How then do you get a package installer/manager when you can't install packages? The solution was in a c.l.p. post.
That link describes a process of creating a new virtual environment and then bootstrapping distribute. In case my link-fu fails me the simple shell based approach is;
$ pyvenv py3k ~/envs/py3k $ cd py3k $ source bin/activate $ wget http://python-distribute.org/distribute_setup.py $ python distribute_setup.py $ ./local/bin/easy_install pip
One final little wrinkle though. The c.l.p. post and other references I found indicate that your package scripts (such as 'pip' and 'python') will be installed in
$ENV_HOME/bin. In my environment they are installed in
$ENV_HOME/local/bin. It's probably something I have inadvertently done. But if you follow the instructions and can't find something in bin have a look in local/bin and you should find it.