Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 1 | .. highlightlang:: sh |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 2 | |
| 3 | .. _using-on-unix: |
| 4 | |
| 5 | ******************************** |
| 6 | Using Python on Unix platforms |
| 7 | ******************************** |
| 8 | |
| 9 | .. sectionauthor:: Shriphani Palakodety |
| 10 | |
| 11 | |
| 12 | Getting and installing the latest version of Python |
| 13 | =================================================== |
| 14 | |
| 15 | On Linux |
| 16 | -------- |
| 17 | |
| 18 | Python comes preinstalled on most Linux distributions, and is available as a |
| 19 | package on all others. However there are certain features you might want to use |
| 20 | that are not available on your distro's package. You can easily compile the |
| 21 | latest version of Python from source. |
Georg Brandl | 06788c9 | 2009-01-03 21:31:47 +0000 | [diff] [blame] | 22 | |
Christian Heimes | 380f7f2 | 2008-02-28 11:19:05 +0000 | [diff] [blame] | 23 | In the event that Python doesn't come preinstalled and isn't in the repositories as |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 24 | well, you can easily make packages for your own distro. Have a look at the |
| 25 | following 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 | |
| 39 | On 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 Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 48 | pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz |
Georg Brandl | 06788c9 | 2009-01-03 21:31:47 +0000 | [diff] [blame] | 49 | |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 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 | |
| 55 | On OpenSolaris |
| 56 | -------------- |
| 57 | |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 58 | To 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 Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 60 | prompt. |
| 61 | |
| 62 | |
| 63 | Building Python |
| 64 | =============== |
| 65 | |
| 66 | If 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 |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 68 | latest release's source or just grab a fresh `clone |
| 69 | <http://docs.python.org/devguide/setup#getting-the-source-code>`_. (If you want |
| 70 | to contribute patches, you will need a clone.) |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 71 | |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 72 | The build process consists in the usual :: |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 73 | |
| 74 | ./configure |
| 75 | make |
| 76 | make install |
| 77 | |
| 78 | invocations. Configuration options and caveats for specific Unix platforms are |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 79 | extensively documented in the :source:`README` file in the root of the Python |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 80 | source tree. |
| 81 | |
| 82 | .. warning:: |
| 83 | |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 84 | ``make install`` can overwrite or masquerade the :file:`python3` binary. |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 85 | ``make altinstall`` is therefore recommended instead of ``make install`` |
| 86 | since it only installs :file:`{exec_prefix}/bin/python{version}`. |
| 87 | |
| 88 | |
| 89 | Python-related paths and files |
| 90 | ============================== |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 91 | |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 92 | These are subject to difference depending on local installation conventions; |
| 93 | :envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``) |
| 94 | are installation-dependent and should be interpreted as for GNU software; they |
| 95 | may be the same. |
| 96 | |
| 97 | For example, on most Linux systems, the default for both is :file:`/usr`. |
| 98 | |
| 99 | +-----------------------------------------------+------------------------------------------+ |
| 100 | | File/directory | Meaning | |
| 101 | +===============================================+==========================================+ |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 102 | | :file:`{exec_prefix}/bin/python3` | Recommended location of the interpreter. | |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 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 | +-----------------------------------------------+------------------------------------------+ |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 112 | |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 113 | |
| 114 | Miscellaneous |
| 115 | ============= |
| 116 | |
| 117 | To easily use Python scripts on Unix, you need to make them executable, |
| 118 | e.g. with :: |
| 119 | |
| 120 | $ chmod +x script |
| 121 | |
| 122 | and put an appropriate Shebang line at the top of the script. A good choice is |
| 123 | usually :: |
| 124 | |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 125 | #!/usr/bin/env python3 |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 126 | |
| 127 | which searches for the Python interpreter in the whole :envvar:`PATH`. However, |
| 128 | some Unices may not have the :program:`env` command, so you may need to hardcode |
Éric Araujo | eb933de | 2011-09-09 19:03:41 +0200 | [diff] [blame] | 129 | ``/usr/bin/python3`` as the interpreter path. |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 130 | |
Ezio Melotti | 0639d5a | 2009-12-19 23:26:38 +0000 | [diff] [blame] | 131 | To use shell commands in your Python scripts, look at the :mod:`subprocess` module. |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 132 | |
| 133 | |
| 134 | Editors |
| 135 | ======= |
| 136 | |
| 137 | Vim and Emacs are excellent editors which support Python very well. For more |
Ezio Melotti | 0639d5a | 2009-12-19 23:26:38 +0000 | [diff] [blame] | 138 | information on how to code in Python in these editors, look at: |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 139 | |
Benjamin Peterson | 9203501 | 2008-12-27 16:00:54 +0000 | [diff] [blame] | 140 | * http://www.vim.org/scripts/script.php?script_id=790 |
| 141 | * http://sourceforge.net/projects/python-mode |
Christian Heimes | 8b0facf | 2007-12-04 19:30:01 +0000 | [diff] [blame] | 142 | |
| 143 | Geany is an excellent IDE with support for a lot of languages. For more |
| 144 | information, read: http://geany.uvena.de/ |
| 145 | |
| 146 | Komodo edit is another extremely good IDE. It also has support for a lot of |
| 147 | languages. For more information, read: |
| 148 | http://www.activestate.com/store/productdetail.aspx?prdGuid=20f4ed15-6684-4118-a78b-d37ff4058c5f |