Skip to content


How to:python programming under Ubuntu

If you are new to python programming & you’re having ubuntu linux as your operating system then you can start programming easily as Ubuntu comes up with the command line version of python pre-installed.Ubuntu community develops its own tools and scripts under python,so you can learn a lot from the community.Community also offers bounties on some of its python projects.So in that way you can also get in touch with the python developers.

In python you have two choices to learn how to program,one is with command line version and another is IDLE.I’ll explain both these methods one by one.

Command Line

Command line version of python is already installed in ubuntu.To get into python’s interactive mode,Click on Appliations>Accesorries>Terminal.Then type ‘python’ without quotes,that will open up the interactive mode of the python.Now you can test your python scripts.

You can also write the program with help of text editor like gedit or emacs.Then save it with extension .py.Now if you want to execute that file,then open the terminal,move yourself to the directory where that .py file exists.Then type the following commands in terminal.
python hello.py
this will execute the program.Once program is executed you’ll return back to the command prompt.To exit from the python interpreter type the following:
import sys;sys.exit();

or  you can use exit(); or CTRL-D
This will exit from the interpreter and return back to the terminal.
IDLE

If you don’t want to use the command line version of python then there is another choice “IDLE”.IDLE means interactive developement envirement.IDLE is a Python IDE that includes a GUI debugger based on pdb.IDLE is not installed in ubuntu by default,you have to install it from DVD.To install the IDLE,follow these steps.
Click on Application>Add-remove applications.

In Add-remove applcations select categary > Programming >then Select “IDLE” check-box point.Click OK.Then it will ask for the install disk and then installs it from there.

Now you can write your program with help of text editor like emacs/gedit.Once you’re done with it,save it with extension .py.Now right click “Open with” then  select >IDLE. OR you can open the file from IDLE.IDLE shows the colored syntax of your program.Now to run your program,follow these steps:
Click>RUN>Run Module.

This will execute the program in the IDLE.

(Graphical user interface-GUI for Python)

Once you learn the techniques of the text processing in python.Then you need to learn how to program applications in GUI.To program GUI based applcations you have many option like Wxpython,Tkinter,Pyqt etc.

Tkinter is a GUI widget set for Python.There are many introductory tutorials for the Tkinter on the web. Some of them are :

[1] Introduction to python

[2] Python and Tkinter Programming by John Grayson (Manning, 2000, ISBN 1-884777-81-3)

[3] Tkinter reference [Here]

WxPython is another GUI toolkit for the Python programming language which allows easy creation of graphical user interfaces.You can obtain more information about Wxpython here.http://wxpython.org

You can learn more from python community so check out the activestate’s “CookBook” where you can learn a lot about the python coding.

I hope above information helps.If you have any quesstion & suggestion or errors.Then please don’t hesitate to post it over here.


28 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Henk Dafour says

    I am just learning to program with Python and found IDLE a bit counter intuitive. My professor advised me SPE: http://pythonide.stani.be I am very happy with it as especially the uml gives a nice overview of my program. There are still a lot of features to explore, but I am sure one day I’ll know more about them.

  2. Harish says

    i’ve just started off with python. the above info was exactly what i was lookin for. thanks

  3. Roy says

    Thank you very much, this really helped me to start with programming in Python. I look for forward for more tutorials of you. Keep ‘em comin’!

  4. Tarandeep Gill says

    Hi,

    I have started learning to program with Python. Your information was highly useful.

  5. Thura says

    Thanks

  6. kirubakaran says

    really thanks…..

  7. Paddy says

    Thanks, this was exactly what I was looking for ;)

  8. Madlib says

    Thanks for the info. This is exactly what python beginners need. Thanks for the useful info.

  9. leegurus says

    thanks dude!!

  10. Offrocker says

    I just discovered Ubuntu 2 weeks ago and am interested in using python,…much thanks.

  11. razorxpress says

    Another nice option for python ide is eclipse. Installing eclipse and adding pydev(without any additional features) plugin helps to write python programs with features of eclipse as in other languages

  12. silvio says

    thank you, very useful

  13. Chris says

    Thanks for the info although I would like to develop Gnome apps in Python, how would I go about doing this?

  14. Rishiraj says

    Great info for a beginner with Linux and Python.It really helped

  15. sup says

    thanks so much. very useful and easy for a beginner.

  16. dave00 says

    Hi!

    This is a simple and very useful article. Thank you!

  17. sreenivasrao says

    Simple and effective for newbie, nice stuff

  18. Karn Chandra says

    Thanks! :)

  19. bob says

    There is another option to try -
    using Netbeans Python early access:
    http://dlc.sun.com.edgesuite.net/netbeans/6.5/python/ea/

  20. Sol says

    With python I can build a program for many platforms.. almost!
    This article is helpful… Thanks a lot!

  21. Brad Blosser says

    Thank you so much for this.
    I’m looking to start a Computer Science degree and I found a wonderful book through MIT called Think Python.

    IT was originally titled Think like a Computer Scientist – Python.

    He charges 90 for it on Amazon so Thank God he believes in open source and open GL because he provides it for free. He even lists your name in his book if you come up with a helpful change and he replies to your comments, a very nice Computer Science teacher.

    Any way…. one thing he forgot in chapter two is how to get your script to work after you create a “simple.py” script, how do you run it.
    I could find nothing that made sense in a windows environment after two days of researching over the weekend. Now I start looking up in the Linux enivronment and (DOH DOH DOH) first try I find the answers to my questions.

    Sigh, I just wish it was easier to play windows games in linux environment and I’d give up windows altogether.
    You’ve almost got me.
    Brad

  22. black scorpio says

    Thank you for this nice information as a beginer like me.

  23. mastr0 says

    thanx for that man

  24. Nattyspats says

    Thank you! Quite helpful.

  25. Abhinav says

    python kicks a** . I thot C++ was easiest but hey pythons more logical and easier :P

  26. Tobin says

    Exactly what I was looking for. Thanks heaps :D

  27. Avinash T M says

    Thanks for nice introduction regarding python,

Continuing the Discussion

  1. » running google app engine in ubuntu Elzo Valugi linked to this post on June 22, 2009

    [...] At least we have a community who helps the apprentices. Help can be found here. [...]



Some HTML is OK

or, reply to this post via trackback.