blob: 6a66a30b9fcaa5760d04cd06909bb542082f652c [file] [log] [blame]
Éric Araujo79c9d4f2011-09-09 19:20:27 +02001.. highlightlang:: sh
Georg Brandld95a1ee2007-12-04 16:10:02 +00002
Georg Brandl21c66652007-12-04 16:50:28 +00003.. _using-on-unix:
Georg Brandld95a1ee2007-12-04 16:10:02 +00004
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.
Georg Brandlc62ef8b2009-01-03 20:55:06 +000022
Georg Brandl3ef20632008-02-26 19:13:45 +000023In the event that Python doesn't come preinstalled and isn't in the repositories as
Georg Brandld95a1ee2007-12-04 16:10:02 +000024well, you can easily make packages for your own distro. Have a look at the
25following links:
26
27.. seealso::
28
Sandro Tosi117e1f02011-12-31 18:13:59 +010029 http://www.debian.org/doc/manuals/maint-guide/first.en.html
Georg Brandld95a1ee2007-12-04 16:10:02 +000030 for Debian users
Ezio Melottic2a4f6b2013-04-13 20:07:42 +030031 http://en.opensuse.org/Portal:Packaging
Georg Brandld95a1ee2007-12-04 16:10:02 +000032 for OpenSuse users
Sandro Tosi117e1f02011-12-31 18:13:59 +010033 http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html
Georg Brandld95a1ee2007-12-04 16:10:02 +000034 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
Georg Brandlc62ef8b2009-01-03 20:55:06 +000048 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
49
Georg Brandld95a1ee2007-12-04 16:10:02 +000050 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
Georg Brandl83ac36d2014-10-28 22:52:49 +010058You can get Python from `OpenCSW <http://www.opencsw.org/>`_. Various versions
59of Python are available and can be installed with e.g. ``pkgutil -i python27``.
Georg Brandld95a1ee2007-12-04 16:10:02 +000060
61
62Building Python
63===============
64
65If you want to compile CPython yourself, first thing you should do is get the
66`source <http://python.org/download/source/>`_. You can download either the
Éric Araujo79c9d4f2011-09-09 19:20:27 +020067latest release's source or just grab a fresh `clone
68<http://docs.python.org/devguide/setup#getting-the-source-code>`_. (If you want
69to contribute patches, you will need a clone.)
Georg Brandld95a1ee2007-12-04 16:10:02 +000070
Éric Araujo79c9d4f2011-09-09 19:20:27 +020071The build process consists in the usual ::
Georg Brandld95a1ee2007-12-04 16:10:02 +000072
73 ./configure
74 make
75 make install
76
77invocations. Configuration options and caveats for specific Unix platforms are
Éric Araujo79c9d4f2011-09-09 19:20:27 +020078extensively documented in the :source:`README` file in the root of the Python
Georg Brandld95a1ee2007-12-04 16:10:02 +000079source tree.
80
Christian Heimes1206a222007-12-04 16:36:20 +000081.. warning::
Georg Brandl21c66652007-12-04 16:50:28 +000082
83 ``make install`` can overwrite or masquerade the :file:`python` binary.
84 ``make altinstall`` is therefore recommended instead of ``make install``
85 since it only installs :file:`{exec_prefix}/bin/python{version}`.
Christian Heimes1206a222007-12-04 16:36:20 +000086
Georg Brandld95a1ee2007-12-04 16:10:02 +000087
88Python-related paths and files
89==============================
Georg Brandlc62ef8b2009-01-03 20:55:06 +000090
Georg Brandld95a1ee2007-12-04 16:10:02 +000091These are subject to difference depending on local installation conventions;
92:envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``)
93are installation-dependent and should be interpreted as for GNU software; they
94may be the same.
95
96For example, on most Linux systems, the default for both is :file:`/usr`.
97
98+-----------------------------------------------+------------------------------------------+
99| File/directory | Meaning |
100+===============================================+==========================================+
101| :file:`{exec_prefix}/bin/python` | Recommended location of the interpreter. |
102+-----------------------------------------------+------------------------------------------+
103| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories |
104| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. |
105+-----------------------------------------------+------------------------------------------+
106| :file:`{prefix}/include/python{version}`, | Recommended locations of the directories |
107| :file:`{exec_prefix}/include/python{version}` | containing the include files needed for |
108| | developing Python extensions and |
109| | embedding the interpreter. |
110+-----------------------------------------------+------------------------------------------+
111| :file:`~/.pythonrc.py` | User-specific initialization file loaded |
112| | by the user module; not used by default |
113| | or by most applications. |
114+-----------------------------------------------+------------------------------------------+
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000115
Georg Brandld95a1ee2007-12-04 16:10:02 +0000116
117Miscellaneous
118=============
119
120To easily use Python scripts on Unix, you need to make them executable,
121e.g. with ::
122
123 $ chmod +x script
124
125and put an appropriate Shebang line at the top of the script. A good choice is
126usually ::
127
128 #!/usr/bin/env python
129
130which searches for the Python interpreter in the whole :envvar:`PATH`. However,
131some Unices may not have the :program:`env` command, so you may need to hardcode
132``/usr/bin/python`` as the interpreter path.
133
Ezio Melotti062d2b52009-12-19 22:41:49 +0000134To use shell commands in your Python scripts, look at the :mod:`subprocess` module.
Georg Brandld95a1ee2007-12-04 16:10:02 +0000135
136
137Editors
138=======
139
140Vim and Emacs are excellent editors which support Python very well. For more
Ezio Melotti062d2b52009-12-19 22:41:49 +0000141information on how to code in Python in these editors, look at:
Georg Brandld95a1ee2007-12-04 16:10:02 +0000142
Georg Brandl1966a232008-12-23 15:44:25 +0000143* http://www.vim.org/scripts/script.php?script_id=790
144* http://sourceforge.net/projects/python-mode
Georg Brandld95a1ee2007-12-04 16:10:02 +0000145
146Geany is an excellent IDE with support for a lot of languages. For more
Sandro Tosi6c625e62012-08-12 11:01:50 +0200147information, read: http://www.geany.org/
Georg Brandld95a1ee2007-12-04 16:10:02 +0000148
149Komodo edit is another extremely good IDE. It also has support for a lot of
150languages. For more information, read:
151http://www.activestate.com/store/productdetail.aspx?prdGuid=20f4ed15-6684-4118-a78b-d37ff4058c5f