Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Downloaded Python 3.3 from the official site but no idea how to install it.

I'm using Ubuntu 12.04

share|improve this question
Why can't I update applications without upgrading the whole OS? explains why it's not available. In short: other packages are relying on an older (still maintained!) version. And please keep your personal thoughts about how this site works for yourself or post it on meta where you can post once you've gained enough reputation points. But first: FAQ on how the site works. – gertvdijk Jan 18 at 8:08
Please stay on topic inside a question. Questions about how AU works and editing works should be posted on meta: meta.askubuntu.com – Rinzwind Jan 18 at 8:44

4 Answers

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, you can either search for a PPA (my quick search found none though) or to 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://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
tar jxf ./Python-3.3.0.tar.bz2
cd ./Python-3.3.0
./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/python ~/bin/py

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

echo 'alias py="/opt/python3.3/bin/python3"' >> .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 :)

There's a software called Pythonbrew which may help you to automate the procedure - what it essentially does is download and compile Python, installing it in your home directory.

share|improve this answer
1  
After installation, how would one use this alternative Python installation? Say I have some .py files with the #!/usr/bin/env python shebang line (executable bit set), how would I make them to use this installation in /opt/python3.3 without modifying all of them? Or even system-installed ones. – gertvdijk Jan 18 at 8:39
1  
@gertvdijk: the whole point is not to replace the default interpreter - if you do that, then every python app ran from your account will use Python 3.3, including Ubuntu apps, such as Software Centre ect. We don't want that. To run a script, just use py myscript.py (where py is a symlink we've created at the end of the exercise). I also normally use virtualenv or buildout for my projects. – Sergey Jan 18 at 8:44
@gertvdijk You can keep multiple python environments manageable using virtualenv. – flup Jan 18 at 13:25
@gertvdijk Are you aware that python 3.x and python 2.x are incompatible? If you were to point all your existing scripts at python 3.3 they'd probably break. Simply shebang your new python scripts as #! /opt/python3.3 and the correct interpreter will be addressed when you run it. – Tony Martin Jan 22 at 21:39
@TonyMartin Yes, I'm totally aware of it and just pretended not to know this. I develop stuff in Python. :) My comment was merely a way to get this into the answer as well. Some people might expect it to be replaced. – gertvdijk Jan 22 at 21:41
show 4 more comments

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!

share|improve this answer
cool, looking good. – mateo_salta Feb 1 at 0:56

The deadsnakes PPA has packages for old and new python versions:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.3
share|improve this answer
It is always better from a ppa. – Natim 2 days ago

Also you can use something like pythonbrew:

curl -kL http://xrl.us/pythonbrewinstall | bash    
echo "[[ -s $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc" >> ~/.bashrc    
pythonbrew install 3.3

It's quite easy to use, and another benefit, that it's possible to install any python version you need. Please see their docs for mode details

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.