How do I install Python 3.3?

I have downloaded Python 3.3 from the official site but no idea how to install it.

I'm using Ubuntu 12.04


Solution 1:

Python 3.3 has been released on 29 September 2012, several months after Ubuntu 12.04 was released. It is included in Ubuntu 12.10 though as python3.3 package

If you want to install Python 3.3 on Ubuntu version which does not have it in its repositories, you have the following options:

Use a PPA

There's a PPA containing Old and New Python versions maintained by Felix Krull. See Luper Rouch's answer for installation instructions.

Compile Python from source

This is very easy and allows you to have multiple Python versions without messing with system python interpreter (which is used by a lot of Ubuntu own programs). On my dev machine I have literally dozens of different Python versions from 2.4 to 3.2 living happily in /opt.

we need C compiler and other stuff to compile Python

sudo apt-get install build-essential

SQLite libs need to be installed in order for Python to have SQLite support.

sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3 # for the command-line client
sudo apt-get install bzip2 libbz2-dev

Download and compile Python:

wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xJf ./Python-3.3.5.tar.xz
cd ./Python-3.3.5
./configure --prefix=/opt/python3.3
make && sudo make install

Some nice touches to install a py command by creating a symlink:

mkdir ~/bin
ln -s /opt/python3.3/bin/python3.3 ~/bin/py

Alternatively, you can install a bash alias named py instead:

echo 'alias py="/opt/python3.3/bin/python3.3"' >> .bashrc

And this is it. Now you can have any Python version, even an alpha, or, say, to have a few copies of Python 3.3 compiled with different settings... not that many people need that though :)

Use pyenv

There's a software called pyenv which may help you to automate the procedure - what it essentially does is compile Python from source, installing it in your home directory. Its goal is to help you manage multiple Python versions.

Solution 2:

Here is what I did to install Python 3.3 on Ubuntu 12.04:

  1. Install dependencies:

    sudo apt-get build-dep python3.2
    sudo apt-get install libreadline-dev libncurses5-dev libssl1.0.0 tk8.5-dev zlib1g-dev liblzma-dev
    
  2. Download Python 3.3.0:

    wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tgz
    
  3. Extract:

    tar xvfz Python-3.3.0.tgz
    
  4. Configure and Install:

    cd Python-3.3.0
    ./configure --prefix=/opt/python3.3
    make  
    sudo make install
    
  5. Test if it worked:

    /opt/python3.3/bin/python3
    

You should see something similar:

Python 3.3.0 (default, Jan 31 2013, 18:37:42) 
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Some Additional things that are useful... you can create a virtual environment in your home and just activate Python 3.3 on demand..

  1. Create a Virtual Environment in your home:

    /opt/python3.3/bin/pyvenv ~/py33
    
  2. Activate the virtualenv:

    source ~/py33/bin/activate
    
  3. Install distribute tools:

    wget http://python-distribute.org/distribute_setup.py
    python distribute_setup.py
    
  4. Install pip:

    easy_install pip
    
  5. Install any python packages you want (i.e. bottle)

    pip install bottle
    

Enjoy!