Nstalling On Buntu Inux: Add/ Remove Applications
Nstalling On Buntu Inux: Add/ Remove Applications
Modern Linux distributions are backed by vast repositories of precompiled applications, ready to install. The
exact details vary by distribution. In Ubuntu Linux, the easiest way to install Python 3 is through the Add/
Remove application in your Applications menu.
21
When you first launch the Add/Remove application, it will show you a list of preselected applications in
different categories. Some are already installed; most are not. Because the repository contains over 10,000
applications, there are different filters you can apply to see small parts of the repository. The default filter is
“Canonical-maintained applications,” which is a small subset of the total number of applications that are
officially supported by Canonical, the company that creates and maintains Ubuntu Linux.
22
Python 3 is not maintained by Canonical, so the first step is to drop down this filter menu and select “All
Open Source applications.”
Once you’ve widened the filter to include all open source applications, use the Search box immediately after
the filter menu to search for Python 3.
23
Now the list of applications narrows to just those matching Python 3. You’re going to check two packages.
The first is Python (v3.0). This contains the Python interpreter itself.
The second package you want is immediately above: IDLE (using Python-3.0). This is a graphical Python
Shell that you will use throughout this book.
After you’ve checked those two packages, click the Apply Changes button to continue.
24
The
package
manager
will ask
you to
confirm
that you
want to
add both
IDLE
(using
25
Once the packages are
downloaded, the package
manager will automatically begin
installing them.
to launch the
Python Shell, or
click the Close button to exit the package manager.
You can always relaunch the Python Shell by going to your Applications menu, then the Programming
submenu, and selecting IDLE.
26
The
Python Shell is where you will spend most of your time exploring Python. Examples throughout this book
will assume that you can find your way into the Python Shell.
27
0.6. INSTALLING ON OTHER PLATFORMS
Python 3 is available on a number of different platforms. In particular, it is available in virtually every Linux,
BSD, and Solaris-based distribution. For example, RedHat Linux uses the yum package manager. FreeBSD has
its ports and packages collection, SUSE has zypper, and Solaris has pkgadd. A quick web search for Python
3 + your operating system should tell you whether a Python 3 package is available, and if so, how to install it.
The Python Shell is where you can explore Python syntax, get interactive help on commands, and debug
short programs. The graphical Python Shell (named IDLE) also contains a decent text editor that supports
Python syntax coloring and integrates with the Python Shell. If you don’t already have a favorite text editor,
you should give IDLE a try.
First things first. The Python Shell itself is an amazing interactive playground. Throughout this book, you’ll see
examples like this:
>>> 1 + 1
The three angle brackets, >>>, denote the Python Shell prompt. Don’t type that part. That’s just to let you
know that this example is meant to be followed in the Python Shell.
1 + 1 is the part you type. You can type any valid Python expression or command in the Python Shell.
Don’t be shy; it won’t bite! The worst that will happen is you’ll get an error message. Commands get
executed immediately (once you press ENTER); expressions get evaluated immediately, and the Python Shell
prints out the result.
2 is the result of evaluating this expression. As it happens, 1 + 1 is a valid Python expression. The result, of
course, is 2.
28
Let’s try another one.
Hello world!
Pretty simple, no? But there’s lots more you can do in the Python shell. If you ever get stuck — you can’t
remember a command, or you can’t remember the proper arguments to pass a certain function — you can
get interactive help in the Python Shell. Just type help and press ENTER.
>>> help
Type help() for interactive help, or help(object) for help about object.
There are two modes of help. You can get help about a single object, which just prints out the
documentation and returns you to the Python Shell prompt. You can also enter help mode, where instead of
evaluating Python expressions, you just type keywords or command names and it will print out whatever it
knows about that command.
To enter the interactive help mode, type help() and press ENTER.
29
>>> help()
If this is your first time using Python, you should definitely check out
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
of what it does; to list the modules whose summaries contain a given word
help>
Note how the prompt changes from >>> to help>. This reminds you that you’re in the interactive help
mode. Now you can enter any keyword, command, module name, function name — pretty much anything
Python understands — and read documentation on it.
30