Python

From ArchWiki

Jump to: navigation, search

Contents

Introduction

This entry will cover installing Python, and provide some references.

Installation

There are currently two versions of python, the 2.6 version which is currently the default, and the newer 3.0 version which is being actively developed.


Python 2.6

To install the latest stable version of Python, you may safely run;

# pacman -S python

If you would like to build the latest rc/betas from source, visit here. The AUR also contains good PKGBUILDS. If you do decide to build the RC, note that the binary (by default) installs to /usr/local/bin/pythonX.x.

This is the version which is currently used by the python programs contained in Arch but will eventually be superseded by the 3.0 line.


Python3

Python 3.0 is the new version of the language that is incompatible with the 2.6 release. The language is mostly the same, but many details, especially how built-in objects like dictionaries and strings work, have changed considerably, and a lot of deprecated features have finally been removed. Also, the standard library has been reorganized in a few prominent places (Python Website).

To install this version from community you may run:

# pacman -S python3

python3 will happily run alongside the default python install. You need to specify python3 in order to run this version.

Misc. Uses

Python is excellent for emergency situations, or when you simply need to work with files without writing any Perl, Bash, or C. Here are some functions that I have found to be helpful (although this is by no means a comprehensive list);

open - open a file
urllib.urlopen - open a web page, import urllib first
urllib.urlretrieve - download a file (by default, to /tmp, but a directory can be specified), import urllib first
os.listdir - list all files in a given directory, import os first

You will find that Python is used frequently, in applications ranging from the GIMP, to Sage. Python's scalability, popularity, and ease of coding makes it an important addition to all desktops.

More Resources

For GUI programming, try Google.

For Fun

>>> import this
>>> from __future__ import braces
Personal tools