Python Programming/Getting Python

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search
Previous: Overview Index Next: Setting it up

In order to program in Python you need the Python interpreter. If it is not already installed or if the version you are using is obsolete, you will need to obtain and install Python using the methods below:

Contents

[edit] Installing Python in Windows

Go to the Python Homepage or the ActiveState website and get the proper version for your platform. Download it, read the instructions and get it installed.

In order to run Python from the command line, you will need to have the python directory in your PATH. Alternatively, you could use an Integrated Development Environment (IDE) for Python like DrPython[1], eric[2], PyScripter[3], or Python's own IDLE (which ships with every version of Python since 2.3).

The PATH variable can be modified from the Window's System control panel. The advanced tab will contain the button labelled Environment Variables, where you can append the newly created folder to the search path.

If you prefer having a temporary environment, you can create a new command prompt short-cut that automatically executes the following statement:

PATH %PATH%;c:\python26

Changing the "26" for the version of Python you have (26 is 2.6.x, the current version of Python 2)

[edit] Cygwin

By default, the Cygwin installer for Windows does not include Python in the downloads. However, it can be selected from the list of packages.

[edit] Installing Python on Mac

Users on Apple Mac OS X will find that it already ships with Python 2.3 (OS X 10.4 Tiger), but if you want the more recent version head to Python Download Page follow the instruction on the page and in the installers. As a bonus you will also install the Python IDE.

[edit] Installing Python on Unix environments

Python is available as a package for some Linux distributions. In some cases, the distribution CD will contain the python package for installation, while other distributions require downloading the source code and using the compilation scripts.

[edit] Gentoo GNU/Linux

Gentoo is an example of a distribution that installs Python by default - the package system Portage depends on Python.

[edit] Ubuntu GNU/Linux

Users of Ubuntu 6.06 (Dapper Drake) and earlier will notice that Python comes installed by default, only it sometimes is not the latest version. If you would like to update it, just open a terminal and type at the prompt:

$ sudo apt-get update  # This will update the software repository
$ sudo apt-get install python   # This one will actually install python

[edit] Arch GNU/Linux

Arch does not install python by default, but is easily available for installation through the package manager to pacman. As root (or using sudo if you've installed and configured it), type:

$ pacman -Sy python

This will be update package databases and install python. Other versions can be built from source from the Arch User Repository.

[edit] Source code installations

Some platforms do not have a version of Python installed, and do not have pre-compiled binaries. In these cases, you will need to download the source code from the official site. Once the download is complete, you will need to unpack the compressed archive into a folder.

To build Python, simply run the configure script (requires the Bash shell) and compile using make.

Previous: Overview Index Next: Setting it up