blob: 3c7fc413446d059412e23a9dfe02a73f0efb459f [file] [log] [blame]
Éric Araujoeb933de2011-09-09 19:03:41 +02001.. highlightlang:: sh
Christian Heimes8b0facf2007-12-04 19:30:01 +00002
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.
Georg Brandl06788c92009-01-03 21:31:47 +000022
Christian Heimes380f7f22008-02-28 11:19:05 +000023In the event that Python doesn't come preinstalled and isn't in the repositories as
Christian Heimes8b0facf2007-12-04 19:30:01 +000024well, you can easily make packages for your own distro. Have a look at the
25following links:
26
27.. seealso::
28
Sandro Tosi1abde362011-12-31 18:46:50 +010029 http://www.debian.org/doc/manuals/maint-guide/first.en.html
Christian Heimes8b0facf2007-12-04 19:30:01 +000030 for Debian users
Ezio Melottiac3da872013-04-13 20:07:42 +030031 http://en.opensuse.org/Portal:Packaging
Christian Heimes8b0facf2007-12-04 19:30:01 +000032 for OpenSuse users
Sandro Tosi1abde362011-12-31 18:46:50 +010033 http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html
Christian Heimes8b0facf2007-12-04 19:30:01 +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 Brandl48310cd2009-01-03 21:18:54 +000048 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
Georg Brandl06788c92009-01-03 21:31:47 +000049
Christian Heimes8b0facf2007-12-04 19:30:01 +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
Éric Araujoeb933de2011-09-09 19:03:41 +020058To install the newest Python versions on OpenSolaris, install `blastwave
59<http://www.blastwave.org/howto.html>`_ and type ``pkg_get -i python`` at the
Christian Heimes8b0facf2007-12-04 19:30:01 +000060prompt.
61
62
Larry Hastings3732ed22014-03-15 21:13:56 -070063.. _building-python-on-unix:
64
Christian Heimes8b0facf2007-12-04 19:30:01 +000065Building Python
66===============
67
68If you want to compile CPython yourself, first thing you should do is get the
69`source <http://python.org/download/source/>`_. You can download either the
Éric Araujoeb933de2011-09-09 19:03:41 +020070latest release's source or just grab a fresh `clone
71<http://docs.python.org/devguide/setup#getting-the-source-code>`_. (If you want
72to contribute patches, you will need a clone.)
Christian Heimes8b0facf2007-12-04 19:30:01 +000073
Éric Araujoeb933de2011-09-09 19:03:41 +020074The build process consists in the usual ::
Christian Heimes8b0facf2007-12-04 19:30:01 +000075
76 ./configure
77 make
78 make install
79
80invocations. Configuration options and caveats for specific Unix platforms are
Éric Araujoeb933de2011-09-09 19:03:41 +020081extensively documented in the :source:`README` file in the root of the Python
Christian Heimes8b0facf2007-12-04 19:30:01 +000082source tree.
83
84.. warning::
85
Éric Araujoeb933de2011-09-09 19:03:41 +020086 ``make install`` can overwrite or masquerade the :file:`python3` binary.
Christian Heimes8b0facf2007-12-04 19:30:01 +000087 ``make altinstall`` is therefore recommended instead of ``make install``
88 since it only installs :file:`{exec_prefix}/bin/python{version}`.
89
90
91Python-related paths and files
92==============================
Georg Brandl48310cd2009-01-03 21:18:54 +000093
Christian Heimes8b0facf2007-12-04 19:30:01 +000094These are subject to difference depending on local installation conventions;
95:envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``)
96are installation-dependent and should be interpreted as for GNU software; they
97may be the same.
98
99For example, on most Linux systems, the default for both is :file:`/usr`.
100
101+-----------------------------------------------+------------------------------------------+
102| File/directory | Meaning |
103+===============================================+==========================================+
Éric Araujoeb933de2011-09-09 19:03:41 +0200104| :file:`{exec_prefix}/bin/python3` | Recommended location of the interpreter. |
Christian Heimes8b0facf2007-12-04 19:30:01 +0000105+-----------------------------------------------+------------------------------------------+
106| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories |
107| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. |
108+-----------------------------------------------+------------------------------------------+
109| :file:`{prefix}/include/python{version}`, | Recommended locations of the directories |
110| :file:`{exec_prefix}/include/python{version}` | containing the include files needed for |
111| | developing Python extensions and |
112| | embedding the interpreter. |
113+-----------------------------------------------+------------------------------------------+
Georg Brandl48310cd2009-01-03 21:18:54 +0000114
Christian Heimes8b0facf2007-12-04 19:30:01 +0000115
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
Éric Araujoeb933de2011-09-09 19:03:41 +0200127 #!/usr/bin/env python3
Christian Heimes8b0facf2007-12-04 19:30:01 +0000128
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
Éric Araujoeb933de2011-09-09 19:03:41 +0200131``/usr/bin/python3`` as the interpreter path.
Christian Heimes8b0facf2007-12-04 19:30:01 +0000132
Ezio Melotti0639d5a2009-12-19 23:26:38 +0000133To use shell commands in your Python scripts, look at the :mod:`subprocess` module.
Christian Heimes8b0facf2007-12-04 19:30:01 +0000134
135
136Editors
137=======
138
139Vim and Emacs are excellent editors which support Python very well. For more
Ezio Melotti0639d5a2009-12-19 23:26:38 +0000140information on how to code in Python in these editors, look at:
Christian Heimes8b0facf2007-12-04 19:30:01 +0000141
Benjamin Peterson92035012008-12-27 16:00:54 +0000142* http://www.vim.org/scripts/script.php?script_id=790
143* http://sourceforge.net/projects/python-mode
Christian Heimes8b0facf2007-12-04 19:30:01 +0000144
145Geany is an excellent IDE with support for a lot of languages. For more
Sandro Tosi8b2c71a2012-08-12 11:02:03 +0200146information, read: http://www.geany.org/
Christian Heimes8b0facf2007-12-04 19:30:01 +0000147
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