Éric Araujo | 79c9d4f | 2011-09-09 19:20:27 +0200 | [diff] [blame] | 1 | .. highlightlang:: sh |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 2 | |
Georg Brandl | 21c6665 | 2007-12-04 16:50:28 +0000 | [diff] [blame] | 3 | .. _using-on-unix: |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 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 | c62ef8b | 2009-01-03 20:55:06 +0000 | [diff] [blame] | 22 | |
Georg Brandl | 3ef2063 | 2008-02-26 19:13:45 +0000 | [diff] [blame] | 23 | In the event that Python doesn't come preinstalled and isn't in the repositories as |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +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 | |
Sandro Tosi | 117e1f0 | 2011-12-31 18:13:59 +0100 | [diff] [blame] | 29 | http://www.debian.org/doc/manuals/maint-guide/first.en.html |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 30 | for Debian users |
Ezio Melotti | c2a4f6b | 2013-04-13 20:07:42 +0300 | [diff] [blame] | 31 | http://en.opensuse.org/Portal:Packaging |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 32 | for OpenSuse users |
Sandro Tosi | 117e1f0 | 2011-12-31 18:13:59 +0100 | [diff] [blame] | 33 | http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 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 | c62ef8b | 2009-01-03 20:55:06 +0000 | [diff] [blame] | 48 | pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz |
| 49 | |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +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 | |
Georg Brandl | 83ac36d | 2014-10-28 22:52:49 +0100 | [diff] [blame] | 58 | You can get Python from `OpenCSW <http://www.opencsw.org/>`_. Various versions |
| 59 | of Python are available and can be installed with e.g. ``pkgutil -i python27``. |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 60 | |
| 61 | |
Ned Deily | 3f1d0b3 | 2014-11-20 02:11:03 -0800 | [diff] [blame] | 62 | .. _building-python-on-unix: |
| 63 | |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 64 | Building Python |
| 65 | =============== |
| 66 | |
| 67 | If you want to compile CPython yourself, first thing you should do is get the |
Georg Brandl | 06f3b3b | 2014-10-29 08:36:35 +0100 | [diff] [blame] | 68 | `source <https://www.python.org/download/source/>`_. You can download either the |
Éric Araujo | 79c9d4f | 2011-09-09 19:20:27 +0200 | [diff] [blame] | 69 | latest release's source or just grab a fresh `clone |
Georg Brandl | 97ae466 | 2014-10-29 10:26:56 +0100 | [diff] [blame] | 70 | <https://docs.python.org/devguide/setup.html#getting-the-source-code>`_. (If you want |
Éric Araujo | 79c9d4f | 2011-09-09 19:20:27 +0200 | [diff] [blame] | 71 | to contribute patches, you will need a clone.) |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 72 | |
Éric Araujo | 79c9d4f | 2011-09-09 19:20:27 +0200 | [diff] [blame] | 73 | The build process consists in the usual :: |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 74 | |
| 75 | ./configure |
| 76 | make |
| 77 | make install |
| 78 | |
| 79 | invocations. Configuration options and caveats for specific Unix platforms are |
Éric Araujo | 79c9d4f | 2011-09-09 19:20:27 +0200 | [diff] [blame] | 80 | extensively documented in the :source:`README` file in the root of the Python |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 81 | source tree. |
| 82 | |
Christian Heimes | 1206a22 | 2007-12-04 16:36:20 +0000 | [diff] [blame] | 83 | .. warning:: |
Georg Brandl | 21c6665 | 2007-12-04 16:50:28 +0000 | [diff] [blame] | 84 | |
| 85 | ``make install`` can overwrite or masquerade the :file:`python` binary. |
| 86 | ``make altinstall`` is therefore recommended instead of ``make install`` |
| 87 | since it only installs :file:`{exec_prefix}/bin/python{version}`. |
Christian Heimes | 1206a22 | 2007-12-04 16:36:20 +0000 | [diff] [blame] | 88 | |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 89 | |
| 90 | Python-related paths and files |
| 91 | ============================== |
Georg Brandl | c62ef8b | 2009-01-03 20:55:06 +0000 | [diff] [blame] | 92 | |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 93 | These are subject to difference depending on local installation conventions; |
| 94 | :envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``) |
| 95 | are installation-dependent and should be interpreted as for GNU software; they |
| 96 | may be the same. |
| 97 | |
| 98 | For example, on most Linux systems, the default for both is :file:`/usr`. |
| 99 | |
| 100 | +-----------------------------------------------+------------------------------------------+ |
| 101 | | File/directory | Meaning | |
| 102 | +===============================================+==========================================+ |
| 103 | | :file:`{exec_prefix}/bin/python` | Recommended location of the interpreter. | |
| 104 | +-----------------------------------------------+------------------------------------------+ |
| 105 | | :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories | |
| 106 | | :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. | |
| 107 | +-----------------------------------------------+------------------------------------------+ |
| 108 | | :file:`{prefix}/include/python{version}`, | Recommended locations of the directories | |
| 109 | | :file:`{exec_prefix}/include/python{version}` | containing the include files needed for | |
| 110 | | | developing Python extensions and | |
| 111 | | | embedding the interpreter. | |
| 112 | +-----------------------------------------------+------------------------------------------+ |
| 113 | | :file:`~/.pythonrc.py` | User-specific initialization file loaded | |
| 114 | | | by the user module; not used by default | |
| 115 | | | or by most applications. | |
| 116 | +-----------------------------------------------+------------------------------------------+ |
Georg Brandl | c62ef8b | 2009-01-03 20:55:06 +0000 | [diff] [blame] | 117 | |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 118 | |
| 119 | Miscellaneous |
| 120 | ============= |
| 121 | |
| 122 | To easily use Python scripts on Unix, you need to make them executable, |
| 123 | e.g. with :: |
| 124 | |
| 125 | $ chmod +x script |
| 126 | |
| 127 | and put an appropriate Shebang line at the top of the script. A good choice is |
| 128 | usually :: |
| 129 | |
| 130 | #!/usr/bin/env python |
| 131 | |
| 132 | which searches for the Python interpreter in the whole :envvar:`PATH`. However, |
| 133 | some Unices may not have the :program:`env` command, so you may need to hardcode |
| 134 | ``/usr/bin/python`` as the interpreter path. |
| 135 | |
Ezio Melotti | 062d2b5 | 2009-12-19 22:41:49 +0000 | [diff] [blame] | 136 | To use shell commands in your Python scripts, look at the :mod:`subprocess` module. |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 137 | |
| 138 | |
| 139 | Editors |
| 140 | ======= |
| 141 | |
| 142 | Vim and Emacs are excellent editors which support Python very well. For more |
Ezio Melotti | 062d2b5 | 2009-12-19 22:41:49 +0000 | [diff] [blame] | 143 | information on how to code in Python in these editors, look at: |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 144 | |
Georg Brandl | 1966a23 | 2008-12-23 15:44:25 +0000 | [diff] [blame] | 145 | * http://www.vim.org/scripts/script.php?script_id=790 |
| 146 | * http://sourceforge.net/projects/python-mode |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 147 | |
| 148 | Geany is an excellent IDE with support for a lot of languages. For more |
Sandro Tosi | 6c625e6 | 2012-08-12 11:01:50 +0200 | [diff] [blame] | 149 | information, read: http://www.geany.org/ |
Georg Brandl | d95a1ee | 2007-12-04 16:10:02 +0000 | [diff] [blame] | 150 | |
| 151 | Komodo edit is another extremely good IDE. It also has support for a lot of |
Georg Brandl | 97ae466 | 2014-10-29 10:26:56 +0100 | [diff] [blame] | 152 | languages. For more information, read http://komodoide.com/. |