1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<span id="using-on-unix"></span><h1> Using Python on Unix platforms</h1> <section id="getting-and-installing-the-latest-version-of-python"> <h2>
<span class="section-number">2.1. </span>Getting and installing the latest version of Python</h2> <section id="on-linux"> <h3>
<span class="section-number">2.1.1. </span>On Linux</h3> <p>Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features you might want to use that are not available on your distro’s package. You can easily compile the latest version of Python from source.</p> <p>In the event that Python doesn’t come preinstalled and isn’t in the repositories as well, you can easily make packages for your own distro. Have a look at the following links:</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt><a class="reference external" href="https://www.debian.org/doc/manuals/maint-guide/first.en.html">https://www.debian.org/doc/manuals/maint-guide/first.en.html</a></dt>
<dd>
<p>for Debian users</p> </dd> <dt><a class="reference external" href="https://en.opensuse.org/Portal:Packaging">https://en.opensuse.org/Portal:Packaging</a></dt>
<dd>
<p>for OpenSuse users</p> </dd> <dt><a class="reference external" href="https://docs.fedoraproject.org/en-US/package-maintainers/Packaging_Tutorial_GNU_Hello/">https://docs.fedoraproject.org/en-US/package-maintainers/Packaging_Tutorial_GNU_Hello/</a></dt>
<dd>
<p>for Fedora users</p> </dd> <dt><a class="reference external" href="https://slackbook.org/html/package-management-making-packages.html">https://slackbook.org/html/package-management-making-packages.html</a></dt>
<dd>
<p>for Slackware users</p> </dd> </dl> </div> </section> <section id="on-freebsd-and-openbsd"> <h3>
<span class="section-number">2.1.2. </span>On FreeBSD and OpenBSD</h3> <ul> <li>
<p>FreeBSD users, to add the package use:</p> <pre data-language="sh">pkg install python3
</pre> </li> <li>
<p>OpenBSD users, to add the package use:</p> <pre data-language="sh">pkg_add -r python
pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
</pre> <p>For example i386 users get the 2.5.1 version of Python using:</p> <pre data-language="sh">pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
</pre> </li> </ul> </section> </section> <section id="building-python"> <span id="building-python-on-unix"></span><h2>
<span class="section-number">2.2. </span>Building Python</h2> <p>If you want to compile CPython yourself, first thing you should do is get the <a class="reference external" href="https://www.python.org/downloads/source/">source</a>. You can download either the latest release’s source or just grab a fresh <a class="reference external" href="https://devguide.python.org/setup/#get-the-source-code">clone</a>. (If you want to contribute patches, you will need a clone.)</p> <p>The build process consists of the usual commands:</p> <pre data-language="sh">./configure
make
make install
</pre> <p><a class="reference internal" href="configure#configure-options"><span class="std std-ref">Configuration options</span></a> and caveats for specific Unix platforms are extensively documented in the <a class="reference external" href="https://github.com/python/cpython/tree/3.12/README.rst">README.rst</a> file in the root of the Python source tree.</p> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p><code>make install</code> can overwrite or masquerade the <code>python3</code> binary. <code>make altinstall</code> is therefore recommended instead of <code>make install</code> since it only installs <code><em>exec_prefix</em>/bin/python<em>version</em></code>.</p> </div> </section> <section id="python-related-paths-and-files"> <h2>
<span class="section-number">2.3. </span>Python-related paths and files</h2> <p>These are subject to difference depending on local installation conventions; <a class="reference internal" href="configure#cmdoption-prefix"><code>prefix</code></a> and <a class="reference internal" href="configure#cmdoption-exec-prefix"><code>exec_prefix</code></a> are installation-dependent and should be interpreted as for GNU software; they may be the same.</p> <p>For example, on most Linux systems, the default for both is <code>/usr</code>.</p> <table class="docutils align-default"> <thead> <tr>
<th class="head"><p>File/directory</p></th> <th class="head"><p>Meaning</p></th> </tr> </thead> <tr>
<td><p><code><em>exec_prefix</em>/bin/python3</code></p></td> <td><p>Recommended location of the interpreter.</p></td> </tr> <tr>
<td><p><code><em>prefix</em>/lib/python<em>version</em></code>, <code><em>exec_prefix</em>/lib/python<em>version</em></code></p></td> <td><p>Recommended locations of the directories containing the standard modules.</p></td> </tr> <tr>
<td><p><code><em>prefix</em>/include/python<em>version</em></code>, <code><em>exec_prefix</em>/include/python<em>version</em></code></p></td> <td><p>Recommended locations of the directories containing the include files needed for developing Python extensions and embedding the interpreter.</p></td> </tr> </table> </section> <section id="miscellaneous"> <h2>
<span class="section-number">2.4. </span>Miscellaneous</h2> <p>To easily use Python scripts on Unix, you need to make them executable, e.g. with</p> <pre data-language="shell">$ chmod +x script
</pre> <p>and put an appropriate Shebang line at the top of the script. A good choice is usually</p> <pre data-language="sh">#!/usr/bin/env python3
</pre> <p>which searches for the Python interpreter in the whole <span class="target" id="index-0"></span><code>PATH</code>. However, some Unices may not have the <strong class="program">env</strong> command, so you may need to hardcode <code>/usr/bin/python3</code> as the interpreter path.</p> <p>To use shell commands in your Python scripts, look at the <a class="reference internal" href="../library/subprocess#module-subprocess" title="subprocess: Subprocess management."><code>subprocess</code></a> module.</p> </section> <section id="custom-openssl"> <span id="unix-custom-openssl"></span><h2>
<span class="section-number">2.5. </span>Custom OpenSSL</h2> <ol class="arabic"> <li>
<p>To use your vendor’s OpenSSL configuration and system trust store, locate the directory with <code>openssl.cnf</code> file or symlink in <code>/etc</code>. On most distribution the file is either in <code>/etc/ssl</code> or <code>/etc/pki/tls</code>. The directory should also contain a <code>cert.pem</code> file and/or a <code>certs</code> directory.</p> <pre data-language="shell">$ find /etc/ -name openssl.cnf -printf "%h\n"
/etc/ssl
</pre> </li> <li>
<p>Download, build, and install OpenSSL. Make sure you use <code>install_sw</code> and not <code>install</code>. The <code>install_sw</code> target does not override <code>openssl.cnf</code>.</p> <pre data-language="shell">$ curl -O https://www.openssl.org/source/openssl-VERSION.tar.gz
$ tar xzf openssl-VERSION
$ pushd openssl-VERSION
$ ./config \
--prefix=/usr/local/custom-openssl \
--libdir=lib \
--openssldir=/etc/ssl
$ make -j1 depend
$ make -j8
$ make install_sw
$ popd
</pre> </li> <li>
<p>Build Python with custom OpenSSL (see the configure <code>--with-openssl</code> and <code>--with-openssl-rpath</code> options)</p> <pre data-language="shell">$ pushd python-3.x.x
$ ./configure -C \
--with-openssl=/usr/local/custom-openssl \
--with-openssl-rpath=auto \
--prefix=/usr/local/python-3.x.x
$ make -j8
$ make altinstall
</pre> </li> </ol> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Patch releases of OpenSSL have a backwards compatible ABI. You don’t need to recompile Python to update OpenSSL. It’s sufficient to replace the custom OpenSSL installation with a newer version.</p> </div> </section> <div class="_attribution">
<p class="_attribution-p">
© 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br>
<a href="https://docs.python.org/3.12/using/unix.html" class="_attribution-link">https://docs.python.org/3.12/using/unix.html</a>
</p>
</div>
|