source: python/trunk/Doc/using/unix.rst

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 5.6 KB
RevLine 
[391]1.. highlightlang:: sh
[2]2
3.. _using-on-unix:
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 that 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
[391]29 http://www.debian.org/doc/manuals/maint-guide/first.en.html
[2]30 for Debian users
[391]31 http://en.opensuse.org/Portal:Packaging
[2]32 for OpenSuse users
[391]33 http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html
[2]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
[391]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
[2]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
[391]68latest release's source or just grab a fresh `clone
69<http://docs.python.org/devguide/setup#getting-the-source-code>`_. (If you want
70to contribute patches, you will need a clone.)
[2]71
[391]72The build process consists in the usual ::
[2]73
74 ./configure
75 make
76 make install
77
78invocations. Configuration options and caveats for specific Unix platforms are
[391]79extensively documented in the :source:`README` file in the root of the Python
[2]80source tree.
81
82.. warning::
83
84 ``make install`` can overwrite or masquerade the :file:`python` binary.
85 ``make altinstall`` is therefore recommended instead of ``make install``
86 since it only installs :file:`{exec_prefix}/bin/python{version}`.
87
88
89Python-related paths and files
90==============================
91
92These are subject to difference depending on local installation conventions;
93:envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``)
94are installation-dependent and should be interpreted as for GNU software; they
95may be the same.
96
97For example, on most Linux systems, the default for both is :file:`/usr`.
98
99+-----------------------------------------------+------------------------------------------+
100| File/directory | Meaning |
101+===============================================+==========================================+
102| :file:`{exec_prefix}/bin/python` | Recommended location of the interpreter. |
103+-----------------------------------------------+------------------------------------------+
104| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories |
105| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. |
106+-----------------------------------------------+------------------------------------------+
107| :file:`{prefix}/include/python{version}`, | Recommended locations of the directories |
108| :file:`{exec_prefix}/include/python{version}` | containing the include files needed for |
109| | developing Python extensions and |
110| | embedding the interpreter. |
111+-----------------------------------------------+------------------------------------------+
112| :file:`~/.pythonrc.py` | User-specific initialization file loaded |
113| | by the user module; not used by default |
114| | or by most applications. |
115+-----------------------------------------------+------------------------------------------+
116
117
118Miscellaneous
119=============
120
121To easily use Python scripts on Unix, you need to make them executable,
122e.g. with ::
123
124 $ chmod +x script
125
126and put an appropriate Shebang line at the top of the script. A good choice is
127usually ::
128
129 #!/usr/bin/env python
130
131which searches for the Python interpreter in the whole :envvar:`PATH`. However,
132some Unices may not have the :program:`env` command, so you may need to hardcode
133``/usr/bin/python`` as the interpreter path.
134
135To use shell commands in your Python scripts, look at the :mod:`subprocess` module.
136
137
138Editors
139=======
140
141Vim and Emacs are excellent editors which support Python very well. For more
142information on how to code in Python in these editors, look at:
143
144* http://www.vim.org/scripts/script.php?script_id=790
145* http://sourceforge.net/projects/python-mode
146
147Geany is an excellent IDE with support for a lot of languages. For more
[391]148information, read: http://www.geany.org/
[2]149
150Komodo edit is another extremely good IDE. It also has support for a lot of
151languages. For more information, read:
152http://www.activestate.com/store/productdetail.aspx?prdGuid=20f4ed15-6684-4118-a78b-d37ff4058c5f
Note: See TracBrowser for help on using the repository browser.