How To: Python Programming Under Ubuntu

If you are new to python programming and if you’re using 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. Official Community also offers bounties on some of its python projects. So in that way you can also get in touch with the experienced 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 from official wxpython website.

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

More Python Tutorials

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

  • Henk Dafour

    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.

  • Harish

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

  • Roy

    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’!

  • Thura

    Thanks

  • kirubakaran

    really thanks…..

  • Paddy

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

  • Madlib

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

  • http://ya.com leegurus

    thanks dude!!

  • Offrocker

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

  • razorxpress

    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

  • silvio

    thank you, very useful

  • Chris

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

  • Rishiraj

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

  • http://thaiwebcreator.com sup

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

  • dave00

    Hi!

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

  • sreenivasrao

    Simple and effective for newbie, nice stuff

  • Karn Chandra

    Thanks! :)

  • bob

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

  • Sol

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

  • Pingback: » running google app engine in ubuntu Elzo Valugi

  • Brad Blosser

    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

  • black scorpio

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

  • mastr0

    thanx for that man

  • Nattyspats

    Thank you! Quite helpful.

  • Abhinav

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

  • Tobin

    Exactly what I was looking for. Thanks heaps :D

  • Avinash T M

    Thanks for nice introduction regarding python,