Python

From ArchWiki
Revision as of 09:41, 28 January 2012 by Pmav99 (Talk | contribs) (Integrated Development Environments)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Summary help replacing me
This article explains how to install and configure Python.
Related
Python Package Guidelines
mod_python
Python VirtualEnv

Python "is a remarkably powerful dynamic programming language that is used in a wide variety of application domains. Python is often compared to Tcl, Perl, Ruby, Scheme or Java."

Installation

There are currently two versions of Python: Python 3 (which is the default) and the older Python 2.

Python 3

Python 3 is the latest version of the language, and is incompatible with Python 2. 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. For an overview of the differences, visit Python2orPython3 and their relevant chapter in Dive into Python 3.

To install the latest version of Python 3, install the python package from the official repositories.

If you would like to build the latest RC/betas from source, visit Python Downloads. The Arch User Repository also contains good PKGBUILDs. If you do decide to build the RC, note that the binary (by default) installs to /usr/local/bin/python3.x.

Python 2

To install the latest version of Python 2, install the python2 package from the official repositories.

Python 2 will happily run alongside Python 3. You need to specify python2 in order to run this version.

Any program requiring Python 2 needs to point to /usr/bin/python2, instead of /usr/bin/python.

To do so, open the program or script in a text editor and change the first line.

The line will show one of the following:

#!/usr/bin/env python

or

#!/usr/bin/python

In both cases, just change python to python2 and the program will then use Python 2 instead of Python 3.

Integrated Development Environments

There are some IDEs for Python available in the official repositories.

Eric

For the latest Python 3 compatible version, install the eric package.

Version 4 of Eric is Python 2 compatible and can be installed with the eric4 package.

These IDEs can also handle Ruby.

Ninja

The Ninja IDE is provided by the package ninja-ide.

Spyder

Spyder (previously known as Pydee) is a powerful interactive development environment for the Python language with advanced editing, interactive testing, debugging and introspection features. It focuses on scientific computations, providing a matlab-like environment. It can be installed with the package spyder

Getting easy_install

The easy_install tool is available in the package python-distribute or python2-distribute.

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 make it an important addition to all desktops.

Widget bindings

The following widget toolkit bindings are available:

http://wiki.python.org/moin/TkInter || standard module
http://www.riverbankcomputing.co.uk/software/pyqt/intro || pyqt
http://www.pygtk.org/ || pygtk
http://wxpython.org/ || wxpython

To use these with Python, you may need to install the associated widget kits.

More Resources

For Fun

Try the following snippets from Python's interactive shell:

>>> import this
>>> from __future__ import braces
>>> import antigravity