blob: 8a452dc1e659cde07ad444d579a61a2c1cb1426d [file] [log] [blame]
Georg Brandld95a1ee2007-12-04 16:10:02 +00001.. highlightlang:: none
2
3.. _using-on-windows:
4
5********************************
6 Using Python on Unix platforms
7********************************
8
9.. sectionauthor:: Shriphani Palakodety
10
11
12Getting and installing the latest version of Python
13===================================================
14
15On Linux
16--------
17
18Python comes preinstalled on most Linux distributions, and is available as a
19package on all others. However there are certain features you might want to use
20that are not available on your distro's package. You can easily compile the
21latest version of Python from source.
22
23In the event Python doesn't come preinstalled and isn't in the repositories as
24well, you can easily make packages for your own distro. Have a look at the
25following links:
26
27.. seealso::
28
29 http://www.linux.com/articles/60383
30 for Debian users
31 http://linuxmafia.com/pub/linux/suse-linux-internals/chapter35.html
32 for OpenSuse users
33 http://docs.fedoraproject.org/drafts/rpm-guide-en/ch-creating-rpms.html
34 for Fedora users
35 http://www.slackbook.org/html/package-management-making-packages.html
36 for Slackware users
37
38
39On FreeBSD and OpenBSD
40----------------------
41
42* FreeBSD users, to add the package use::
43
44 pkg_add -r python
45
46* OpenBSD users use::
47
48 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
49
50 For example i386 users get the 2.5.1 version of Python using::
51
52 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
53
54
55On OpenSolaris
56--------------
57
58To install the newest Python versions on OpenSolaris, install blastwave
59(http://www.blastwave.org/howto.html) and type "pkg_get -i python" at the
60prompt.
61
62
63Building Python
64===============
65
66If you want to compile CPython yourself, first thing you should do is get the
67`source <http://python.org/download/source/>`_. You can download either the
68latest release's source or just grab a fresh `checkout
69<http://www.python.org/dev/faq/#how-do-i-get-a-checkout-of-the-repository-read-only-and-read-write>`_.
70
71The build process consists the usual ::
72
73 ./configure
74 make
75 make install
76
77invocations. Configuration options and caveats for specific Unix platforms are
78extensively documented in the :file:`README` file in the root of the Python
79source tree.
80
Christian Heimes1206a222007-12-04 16:36:20 +000081.. warning::
82 ``make install`` can overwrite or masquerade the :file:`python` binary;
83 ``make altinstall`` is recommended instead of ``make install`` since it
84 only install :file:`{exec_prefix}/bin/python{version}`.
85
Georg Brandld95a1ee2007-12-04 16:10:02 +000086
87Python-related paths and files
88==============================
89
90These are subject to difference depending on local installation conventions;
91:envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``)
92are installation-dependent and should be interpreted as for GNU software; they
93may be the same.
94
95For example, on most Linux systems, the default for both is :file:`/usr`.
96
97+-----------------------------------------------+------------------------------------------+
98| File/directory | Meaning |
99+===============================================+==========================================+
100| :file:`{exec_prefix}/bin/python` | Recommended location of the interpreter. |
101+-----------------------------------------------+------------------------------------------+
102| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories |
103| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. |
104+-----------------------------------------------+------------------------------------------+
105| :file:`{prefix}/include/python{version}`, | Recommended locations of the directories |
106| :file:`{exec_prefix}/include/python{version}` | containing the include files needed for |
107| | developing Python extensions and |
108| | embedding the interpreter. |
109+-----------------------------------------------+------------------------------------------+
110| :file:`~/.pythonrc.py` | User-specific initialization file loaded |
111| | by the user module; not used by default |
112| | or by most applications. |
113+-----------------------------------------------+------------------------------------------+
114
115
116Miscellaneous
117=============
118
119To easily use Python scripts on Unix, you need to make them executable,
120e.g. with ::
121
122 $ chmod +x script
123
124and put an appropriate Shebang line at the top of the script. A good choice is
125usually ::
126
127 #!/usr/bin/env python
128
129which searches for the Python interpreter in the whole :envvar:`PATH`. However,
130some Unices may not have the :program:`env` command, so you may need to hardcode
131``/usr/bin/python`` as the interpreter path.
132
133To use shell commands in your python scripts, look at the :mod:`subprocess` module.
134
135
136Editors
137=======
138
139Vim and Emacs are excellent editors which support Python very well. For more
140information on how to code in python in these editors, look at:
141
142http://www.vim.org/scripts/script.php?script_id=790
143http://sourceforge.net/projects/python-mode
144
145Geany is an excellent IDE with support for a lot of languages. For more
146information, read: http://geany.uvena.de/
147
148Komodo edit is another extremely good IDE. It also has support for a lot of
149languages. For more information, read:
150http://www.activestate.com/store/productdetail.aspx?prdGuid=20f4ed15-6684-4118-a78b-d37ff4058c5f