blob: 7719baa8cdebbba3dbf4b7a9c7c5af300eab1d37 [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
Georg Brandl6e0b44e2016-02-26 19:37:12 +010029 https://www.debian.org/doc/manuals/maint-guide/first.en.html
Georg Brandld95a1ee2007-12-04 16:10:02 +000030 for Debian users
Georg Brandl6e0b44e2016-02-26 19:37:12 +010031 https://en.opensuse.org/Portal:Packaging
Georg Brandld95a1ee2007-12-04 16:10:02 +000032 for OpenSuse users
Georg Brandl6e0b44e2016-02-26 19:37:12 +010033 https://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
Miss Islington (bot)87711252018-02-13 19:55:09 -080044 pkg install python3
Georg Brandld95a1ee2007-12-04 16:10:02 +000045
Miss Islington (bot)87711252018-02-13 19:55:09 -080046* OpenBSD users, to add the package use::
47
48 pkg_add -r python
Georg Brandld95a1ee2007-12-04 16:10:02 +000049
Georg Brandlc62ef8b2009-01-03 20:55:06 +000050 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
51
Georg Brandld95a1ee2007-12-04 16:10:02 +000052 For example i386 users get the 2.5.1 version of Python using::
53
54 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
55
56
57On OpenSolaris
58--------------
59
Serhiy Storchakab4905ef2016-05-07 10:50:12 +030060You can get Python from `OpenCSW <https://www.opencsw.org/>`_. Various versions
Georg Brandl83ac36d2014-10-28 22:52:49 +010061of Python are available and can be installed with e.g. ``pkgutil -i python27``.
Georg Brandld95a1ee2007-12-04 16:10:02 +000062
63
Ned Deily3f1d0b32014-11-20 02:11:03 -080064.. _building-python-on-unix:
65
Georg Brandld95a1ee2007-12-04 16:10:02 +000066Building Python
67===============
68
69If you want to compile CPython yourself, first thing you should do is get the
Georg Brandl6e0b44e2016-02-26 19:37:12 +010070`source <https://www.python.org/downloads/source/>`_. You can download either the
Éric Araujo79c9d4f2011-09-09 19:20:27 +020071latest release's source or just grab a fresh `clone
Georg Brandl97ae4662014-10-29 10:26:56 +010072<https://docs.python.org/devguide/setup.html#getting-the-source-code>`_. (If you want
Éric Araujo79c9d4f2011-09-09 19:20:27 +020073to contribute patches, you will need a clone.)
Georg Brandld95a1ee2007-12-04 16:10:02 +000074
Éric Araujo79c9d4f2011-09-09 19:20:27 +020075The build process consists in the usual ::
Georg Brandld95a1ee2007-12-04 16:10:02 +000076
77 ./configure
78 make
79 make install
80
81invocations. Configuration options and caveats for specific Unix platforms are
Éric Araujo79c9d4f2011-09-09 19:20:27 +020082extensively documented in the :source:`README` file in the root of the Python
Georg Brandld95a1ee2007-12-04 16:10:02 +000083source tree.
84
Christian Heimes1206a222007-12-04 16:36:20 +000085.. warning::
Georg Brandl21c66652007-12-04 16:50:28 +000086
87 ``make install`` can overwrite or masquerade the :file:`python` binary.
88 ``make altinstall`` is therefore recommended instead of ``make install``
89 since it only installs :file:`{exec_prefix}/bin/python{version}`.
Christian Heimes1206a222007-12-04 16:36:20 +000090
Georg Brandld95a1ee2007-12-04 16:10:02 +000091
92Python-related paths and files
93==============================
Georg Brandlc62ef8b2009-01-03 20:55:06 +000094
Georg Brandld95a1ee2007-12-04 16:10:02 +000095These are subject to difference depending on local installation conventions;
96:envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``)
97are installation-dependent and should be interpreted as for GNU software; they
98may be the same.
99
100For example, on most Linux systems, the default for both is :file:`/usr`.
101
102+-----------------------------------------------+------------------------------------------+
103| File/directory | Meaning |
104+===============================================+==========================================+
105| :file:`{exec_prefix}/bin/python` | Recommended location of the interpreter. |
106+-----------------------------------------------+------------------------------------------+
107| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories |
108| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. |
109+-----------------------------------------------+------------------------------------------+
110| :file:`{prefix}/include/python{version}`, | Recommended locations of the directories |
111| :file:`{exec_prefix}/include/python{version}` | containing the include files needed for |
112| | developing Python extensions and |
113| | embedding the interpreter. |
114+-----------------------------------------------+------------------------------------------+
115| :file:`~/.pythonrc.py` | User-specific initialization file loaded |
116| | by the user module; not used by default |
117| | or by most applications. |
118+-----------------------------------------------+------------------------------------------+
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000119
Georg Brandld95a1ee2007-12-04 16:10:02 +0000120
121Miscellaneous
122=============
123
124To easily use Python scripts on Unix, you need to make them executable,
125e.g. with ::
126
127 $ chmod +x script
128
129and put an appropriate Shebang line at the top of the script. A good choice is
130usually ::
131
132 #!/usr/bin/env python
133
134which searches for the Python interpreter in the whole :envvar:`PATH`. However,
135some Unices may not have the :program:`env` command, so you may need to hardcode
136``/usr/bin/python`` as the interpreter path.
137
Ezio Melotti062d2b52009-12-19 22:41:49 +0000138To use shell commands in your Python scripts, look at the :mod:`subprocess` module.
Georg Brandld95a1ee2007-12-04 16:10:02 +0000139
140
Senthil Kumaran1bfbe4f2017-01-25 01:46:33 -0800141Editors and IDEs
142================
Georg Brandld95a1ee2007-12-04 16:10:02 +0000143
Senthil Kumaran1bfbe4f2017-01-25 01:46:33 -0800144There are a number of IDEs that support Python programming language.
145Many editors and IDEs provide syntax highlighting, debugging tools, and PEP-8 checks.
Georg Brandld95a1ee2007-12-04 16:10:02 +0000146
Senthil Kumaran1bfbe4f2017-01-25 01:46:33 -0800147Please go to `Python Editors <https://wiki.python.org/moin/PythonEditors>`_ and
148`Integrated Development Environments <https://wiki.python.org/moin/IntegratedDevelopmentEnvironments>`_
149for a comprehensive list.