22

I want to use new functools that provides with the lrucache, I am currently using python 2.6, which doesn't support this,

What is the best way I can upgrade to python 3.2? or is there any other way that I can use the itertools+functools of 3.2 release in python 2.6 distribution

Thank you

1

1 Answer 1

24

Since many programs and libraries rely on Python 2.6 (or python 2.7 in 11.04), and since python 2.x and 3.x are incompatible, you can't upgrade - you can only install python3 alongside python 2.6:

Python 3.1

  • Luckily, the stable release of Python 3 (3.1.2 at the time of writing this) is provided in the repositories. Just install the python3-all  package.

    Your interpreter will be /usr/bin/python3 instead of /usr/bin/python.

    You can also now type python3 in your terminal when you want to launch Py3 instead of Py2.


Python 3.2

  • You can, download any version of the python sources from python.org and run

    ./configure
    make
    sudo make altinstall
    

    To be able to compile the python source, you'll need a few packages:

    sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev libbz2-dev
    

    The altinstall option will install the other version of python alongside your existing ones:

    It makes sense to, instead of downloading the sources, check out the latest development release from the python dev repository every so often:

    svn checkout http://svn.python.org/projects/python/branches/py3k
    

    This will give you the very latest development, unstable, version. you can then cd py3k/ and do the above compilation procedure.

    For this, svn  needs to be installed of course.

3
  • 1
    This answer is great, I upvoted, but I'd like more depth. I can invoke the new Python as 'python3.2', which is fine, but can I set things up so that my personal programs will use this version by default (e.g. get python3.2 as the first 'python' on the PATH) while the system keeps safely using python2.6? I ask not because I don't like typing 'python3.2', but because some Feb 22, 2011 at 23:48
  • 1
    @Tartley Your comment got cut off there, why do you want to do it? Feb 23, 2011 at 15:45
  • 1
    (oops, thanks.) ...but because some tools have e.g. bash scripts, which invoke their Python components using 'python xxx.py', and they only run under Python 3.2. So I want to create an environment (indeed, I want it to be my personal default environment) in which Python 3.2 (and all its scripts, tools, etc) is first on the path, while leaving the system Python 2.6 for the system to use (indeed, by preference, I'd like to strip this from my personal path just to ensure no confusion about which Python I am running) Feb 24, 2011 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .