Monday, February 07, 2011

Install Python 3.2 on Linux [Ubuntu]

First of all, I don't see a point to show you how to install Python on Windows. It's dead easy download the installer from python.org and in few clicks you will have python up and running. Installing Python on Linux is bit different and requires some pre-work to be done.

So Let's get started.
Note: Every Modern Linux had a python Installed. You can verify this by opening your Terminal and typing python. It will open the python shell for you. Do not remove the installed version.
Step 1: Pre-requisites for Ubuntu

To be able to compile Python Source, you will need few packages. Fire up the terminal and execute this command
sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
It will take some time to finish depending upon your bandwidth. :)

Step 2: Downloading Python Sources and extracting them on your disk

Download a tarball from the python site here is a direct link. Once, the download is completed you can extract the files by doing a right-click on the file and then clicking the extract option
OR
Fire up the terminal and execute this command which will download the file first and extract it on the disk.
wget http://www.python.org/ftp/python/3.2/Python-3.2rc2.tgz && tar -xvf Python-3.2rc2.tgz
Step 3: Installing Python 3.2

Fire up a new Terminal and execute the following commands individually.

1.   ./configure
2.   make
3.  sudo make altinstall

Hope this Helps! Please write your comments it will help me improve.

60 comments:

  1. solves the 'missing bits' for the:
    _tkinter
    _gdb

    thanks

    ReplyDelete
  2. thanks for the article.. But when i run the command python in the terminal it still opens the 2.6.6 interpreter by default.. How do i run the programs in python 3.2 interpreter.. thanks in advance

    ReplyDelete
  3. Hi,

    If you are running python script than you just have to change the shebang line to
    #!/usr/local/bin/python3.2

    , and if you are running the python interpreter instead of typing python in the terminal or console type python3.2

    Hope this Helps!. If you still have doubts chat with me on meebo, if i am online or post in your comments i try to help. :)

    Regards,
    Karan

    ReplyDelete
    Replies
    1. Thanks! I was going to install python 3 since 2.7 came up as the default for ubuntu 12.10. At the terminal I tried 'python3' and it switched to latest version.

      Delete
  4. thanks, was able to get 3.2 installed without any problems

    ReplyDelete
  5. Since its launch became official, python 3.2 is no longer a rc(release candidate), hence the link for the tarball as well as the direct link no longer work; heres the corrected link.


    http://www.python.org/ftp/python/3.2/Python-3.2.tgz

    ReplyDelete
  6. Thank you, I'm going to try this.

    What do the libxxxx files do in the sudo command? How did you know they were necessary? (I'm new to Linux (Ubuntu10.04) as well as to Python)

    ReplyDelete
  7. Dear User,

    There is actually nothing to tell you. The best way to find out is try to execute the ./Configure command without installing anything. You will get your answer pretty much. :-)

    Hope this Helps!
    Regards,
    Karan

    ReplyDelete
  8. Had the same issue on the command line of the 'python' command firing up the 2.6.6 interpreter. Should have guessed that python3.1 would do the trick but didnt! Just want to say thanks Karan.

    ReplyDelete
  9. Dear User,

    Do you still face the same problem? It would be good enough if you try to explain me your scenario again. I try to help. :-)

    I don't know which version you installed. If you installed 3.2 then type 'python3.2' it will fire python 3.2 interpreter.

    Hope this Helps!
    Regards,
    Karan

    ReplyDelete
  10. Dont worry it is working fine - I have 3.1 installed and can use python3.1 with success. I was simply expressing my thanks :)

    ReplyDelete
  11. Hi,
    in a reply, executing the './configure' command won't really give him a definite answer because he would first have to navigate 'cd' to the directory his package was in, mine for example was in a very weird directory, 'cd Downloads/shantz-xwinwrap/Pythong-3.2' but also, I am having trouble finding the command to exectue the program itself after the installation.
    Any help?

    ReplyDelete
  12. Hi Pat,

    Yes, You are right i haven't mentioned any steps on how to navigate to the folder. But at the same time i believe it's not required. why? Because i asked him to skip the Prerequisites step only. About your second question if you have installed python 3.2 then fire up your terminal or console whatever, the Linux you are running and type in python3.2 it will fire up the python 3.2 interpreter.

    Hope this Helps!
    Regards,
    Karan

    ReplyDelete
  13. I still need some blanks filled in about install process.

    I downloaded the 3.2 tar to my ~ directory on Ubuntu 10.10.

    I'm currently running the 'make', and will follow with the 'sudo make altinstall'.

    Currently, all of the source in under my ~... which is okay.

    After the 'sudo make altinstall', I will have both Python 2 and Python 3 on my desktop... which is what I want.

    Apparently, I will use 'python' to bring up the currently supported Ubuntu version of Python 2, and 'python3.2' to bring up Python 3.2.

    Question 1 -- (maybe already answered by reading the comments)
    about halfway down, you mention how to completely change the version of python loaded by default... by changing "change the shebang line to
    #!/usr/local/bin/python3.2".

    Correction: The instructions were referring to the .py programs not a script file in /etc or /usr/bin or somewhere hidden that controls the startup of python.

    I think I just answered my own question about WHERE python 3.2 will reside. Further, I realize that I can make devel directories at ~/python2 and ~/python3 to keep the different versions of the scripts apart... and the .py scripts in ~/python3 will all use the new "shebang" line.

    Probably, never mind.

    ReplyDelete
  14. Webtech65, tbh... I really don't know what exactly needs to be filled by me in the install process. Or to what extent you did by posting such a huge comment which i really appreciate. None the less my objective is to make myself and mostly those people who come to this blog to understand the installation process. So, feel free to post in your comments about your experiences so we can also learn.

    Hope this Helps!
    Regards,
    Karan

    ReplyDelete
  15. Hello! Quite nice quick install guide :)

    Few comments though...
    1. this is the updated link:

    wget http://www.python.org/ftp/python/3.2/Python-3.2rc3.tgz && tar -xvf Python-3.2rc3.tgz

    2. you've forgot to mention on the install section that

    ./configure
    make
    sudo make altinstall

    ...must be run in the Python-3.2rc3 folder.

    ReplyDelete
  16. Don't you think it's understood? But if not for anyone than please assume it. Thank you user for your comment. Much Appreciated. :-)

    ReplyDelete
  17. This comment has been removed by a blog administrator.

    ReplyDelete
  18. At the time of writing this post. Only Release Candidate is available.

    ReplyDelete
  19. step2 is not working,.im getting an error in the terminal after running this step2,.the error is...
    404 page not found..
    Please lemme know another way to continue the installation of python 3.2 in my system.

    Thank you,..

    ReplyDelete
  20. Nikhil, That link is not working because python 3.2 launch became official, Here is the corrected link.

    http://www.python.org/ftp/python/3.2/Python-3.2.tgz

    ReplyDelete
  21. Hi,How can I import wx? Am new to python, using ubuntu 11.04 python 3.2, IDLE3.
    With python2.7 no import error. Changing sys.path does not seem to help.
    Current wx sys.path: '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'.

    Any advise? Thanks.

    ReplyDelete
  22. Hi Karan,

    Thank you for your instructions!

    ReplyDelete
  23. If anybody reading this was supposed to know what to do, what was the point of this? Even following these instructions there are steps missing that I can't figure out.

    ReplyDelete
  24. I'd like to thank you a lot for this help

    ReplyDelete
  25. hola es genial
    pero no puedo ver las librerias de gtk y webkit
    alguna solucion a esto???

    saludos

    ReplyDelete
  26. ./configure
    make
    sudo make altinstall

    ...must be run in the Python-3.2rc3 folder.

    How do I do that? Thanks.

    ReplyDelete
  27. How can I make version3.2 as the default interpreter (and not 2.7) ?

    When I type python on a terminal is the version 2.7 that is invoked (I have to explicitly type "python3.2" to get the latests version.

    I have no option to chooce in two steps the version (I have seen somewhere something similar to this I think)

    I hope that you understood, sorry for my English...I tried..

    ReplyDelete
  28. E:couldn't find package build-essential
    am new to linux

    ReplyDelete
  29. If you have ubuntu 64 bit, go to the Python site and download the tarball available for linux.

    $ cd (where you have downloaded it to)
    $ tar xvfz Python 3.2.2.tgz
    $ Python 3.2.2/configure
    $ make
    $ make test #this takes a while
    $ sudo make altinstall

    If you use Aptana Studio, you will have to configure your python interpreter.

    Each python file should have ..
    #!"usr/bin/Python.3.2.2"

    ReplyDelete
    Replies
    1. I tried these steps in ubuntu 12.04.1 LTS
      After $ sudo make altinstall
      it asks [sudo] password:
      but the problem is it neither allows me to write password
      and the msg sorry try again ,later after enter is pressed..
      i am trying to instal python 3.2.3..
      any solution???

      Delete
    2. You never see password typed in Linux terminals.. Just type the password and then press enter it will accept it. A security feature of linux that won't allow leave foot printing that is the reason when you type password in linux it looks like it was not accepting anything.. rest assured it is working. :)

      Delete
    3. Please see this: http://linuxgazette.net/35/tag/passwd.html

      Delete
  30. Thanks ... it helped me a lot while installing it .... then wat about use of network and curses resources????

    ReplyDelete
  31. This comment has been removed by a blog administrator.

    ReplyDelete
  32. Thank you! Helped a lot. Though I needed to read the comments to understand how to do the installing part, but it was ok. Thanks again.

    ReplyDelete
  33. Danke
    mit dem aktuellen Paketnamen gelingt die Installation (Ubuntu lucid) problemfrei

    ReplyDelete
  34. I followed the instructions to install python3.2 (on Ubuntu 10.04) but when I typed $ python3.2 in terminal, the output is: command not found. Can somebody help me??

    ReplyDelete
    Replies
    1. Dear Anonymous User,

      Did you see any error at the time of installation? I don't see any point why it shows command not found. I request you to go through the Installation Procedure again and read out all the comments that others have concerns and do let me know if it solves your problem. If it's still unresolved please revert back here.. I try to see what I can do... :)

      Delete
  35. Hello! Thank u nice quick install guide! :)

    ReplyDelete
  36. Everything went fine upto this point:
    Fire up a new Terminal and execute the following commands individually.

    1. ./configure
    Then I get this -

    bash: ./configure: No such file or directory

    ReplyDelete
    Replies
    1. Hi gareth,

      Sorry for replying you so late but it seems you have not cd to the directory where you have extracted the files otherwise you won't see such error. One thing you can do is to check is to list down (command `ls`) the current directory and see if configure file is present on your path. Please let me know if its still not resolved.

      Delete
  37. Sweet! Thanks for the help!

    ReplyDelete
  38. Thank you so much! All other resources go part way with the install. I was beginning to think that installing 3.2.3 was not possible with Lucid.

    ReplyDelete
  39. Thanks it was of great helo

    ReplyDelete
  40. Hi I managed to install en start the interpreter and it's showing Python 3.3.2 (like I wanted).
    Just can' seem to get it to start default. I still get Python 2.6

    * just for your info; i'm installing on OMV with Putty. Commands work the same.

    regards,

    MassaReal

    ReplyDelete
    Replies
    1. I'm sorry for replying late.

      As this tutorial tells you if you install python 3.2 to bring the newly installed python interpreter you need to type python3.2.

      As you have installed python3.3 try that instead and see if it works. I prefer to check the installation dir and see what name it is.

      Hope this Helps!

      Delete
  41. Hello,

    Can you also tell , how to install simplegui module for python?


    Thanks...

    ReplyDelete
    Replies
    1. Hi User,

      Please refer this page. Download the tool below and install using the given instruction:

      http://florian-berger.de/en/software/simplegui

      Delete
  42. Many thanks! Your instructions worked just fine for installing and running Python 3.3.2 (with the obvious minor changes in version number).

    ReplyDelete
  43. Hi,
    Can you tell me how to install 32bit python on a 64bit Ubuntu machine? I need to install python 2.7.6 32bit. The machine already have python2.7 and python3.3 64bit.

    Ubuntu version is 13.04 (raring)

    ReplyDelete
  44. Hi,
    Can you please tell me how to install 32bit python(2.7) on a 64bit Ubuntu (13.04) machine. The machine already contains python 3.3 and python 2.7 64bit version.

    ReplyDelete
    Replies
    1. Hey Bharathi,

      Try this: http://askubuntu.com/questions/29253/how-can-i-install-a-32bit-python-on-64-bit-ubuntu

      Delete
  45. while trying to install packages,it provides the following type of error.
    kingmaker@kingmaker-HP-Pavilion-15-Notebook-PC:~$ sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Package libreadline5-dev is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:
    libreadline-gplv2-dev:i386 lib64readline-gplv2-dev:i386

    E: Package 'libreadline5-dev' has no installation candidate
    kingmaker@kingmaker-HP-Pavilion-15-Notebook-PC:~$

    please help me to solve it.....

    ReplyDelete
  46. First: Try sudo apt-get update If it won't work share your OS details. :)

    ReplyDelete