[fcc02767] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
| 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
| 4 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
| 8 | <sect1 id="ch-system-Python" role="wrap">
|
---|
| 9 | <?dbhtml filename="Python.html"?>
|
---|
| 10 |
|
---|
| 11 | <sect1info condition="script">
|
---|
| 12 | <productname>Python</productname>
|
---|
| 13 | <productnumber>&python-version;</productnumber>
|
---|
| 14 | <address>&python-url;</address>
|
---|
| 15 | </sect1info>
|
---|
| 16 |
|
---|
| 17 | <title>Python-&python-version;</title>
|
---|
| 18 |
|
---|
| 19 | <indexterm zone="ch-system-Python">
|
---|
[4798321] | 20 | <primary sortas="a-Python">Python</primary>
|
---|
[fcc02767] | 21 | </indexterm>
|
---|
| 22 |
|
---|
| 23 | <sect2 role="package">
|
---|
| 24 | <title/>
|
---|
| 25 |
|
---|
| 26 | <para>The Python 3 package contains the Python development environment. It
|
---|
| 27 | is useful for object-oriented programming, writing scripts, prototyping
|
---|
[8e751f7] | 28 | large programs, and developing entire applications. Python is an interpreted
|
---|
| 29 | computer language.</para>
|
---|
[fcc02767] | 30 |
|
---|
| 31 | <segmentedlist>
|
---|
| 32 | <segtitle>&buildtime;</segtitle>
|
---|
| 33 | <segtitle>&diskspace;</segtitle>
|
---|
| 34 |
|
---|
| 35 | <seglistitem>
|
---|
[fb386e0] | 36 | <seg>&python-fin-sbu;</seg>
|
---|
| 37 | <seg>&python-fin-du;</seg>
|
---|
[fcc02767] | 38 | </seglistitem>
|
---|
| 39 | </segmentedlist>
|
---|
| 40 |
|
---|
| 41 | </sect2>
|
---|
| 42 |
|
---|
| 43 | <sect2 role="installation">
|
---|
| 44 | <title>Installation of Python 3</title>
|
---|
| 45 |
|
---|
| 46 | <para>Prepare Python for compilation:</para>
|
---|
| 47 |
|
---|
[5ed37b3] | 48 | <screen><userinput remap="configure">./configure --prefix=/usr \
|
---|
| 49 | --enable-shared \
|
---|
| 50 | --with-system-expat \
|
---|
| 51 | --with-system-ffi \
|
---|
| 52 | --enable-optimizations</userinput></screen>
|
---|
[fcc02767] | 53 |
|
---|
| 54 | <variablelist>
|
---|
| 55 | <title>The meaning of the configure options:</title>
|
---|
| 56 |
|
---|
| 57 | <varlistentry>
|
---|
| 58 | <term><parameter>--with-system-expat</parameter></term>
|
---|
| 59 | <listitem>
|
---|
[8e751f7] | 60 | <para>This switch enables linking against the system version of
|
---|
[fcc02767] | 61 | <application>Expat</application>.</para>
|
---|
| 62 | </listitem>
|
---|
| 63 | </varlistentry>
|
---|
| 64 |
|
---|
| 65 | <varlistentry>
|
---|
| 66 | <term><parameter>--with-system-ffi</parameter></term>
|
---|
| 67 | <listitem>
|
---|
[8e751f7] | 68 | <para>This switch enables linking against the system version of
|
---|
[30f5283] | 69 | <filename class='libraryfile'>libffi.so</filename>.</para>
|
---|
[fcc02767] | 70 | </listitem>
|
---|
| 71 | </varlistentry>
|
---|
| 72 |
|
---|
[5ed37b3] | 73 | <varlistentry>
|
---|
| 74 | <term><parameter>--enable-optimizations</parameter></term>
|
---|
| 75 | <listitem>
|
---|
[8e751f7] | 76 | <para>This switch enables extensive, but time-consuming, optimization
|
---|
| 77 | steps. The interpreter is built twice; tests performed on the first
|
---|
| 78 | build are used to improve the optimized final version.</para>
|
---|
| 79 | <!-- This description was drawn from the README.rst file
|
---|
| 80 | in the Python-3.11.0 package. -->
|
---|
[5ed37b3] | 81 | </listitem>
|
---|
| 82 | </varlistentry>
|
---|
| 83 |
|
---|
[fcc02767] | 84 | </variablelist>
|
---|
| 85 |
|
---|
| 86 | <para>Compile the package:</para>
|
---|
| 87 |
|
---|
| 88 | <screen><userinput remap="make">make</userinput></screen>
|
---|
| 89 |
|
---|
[5ed37b3] | 90 | <para>Running the tests at this point is not recommended. The
|
---|
| 91 | tests are known to hang indefinitely in the partial LFS environment.
|
---|
[8e751f7] | 92 | If desired, the tests can be rerun at the end of this chapter, or
|
---|
[5ed37b3] | 93 | when Python 3 is reinstalled in BLFS. To run the tests anyway,
|
---|
| 94 | issue <command>make test</command>.</para>
|
---|
[fcc02767] | 95 |
|
---|
| 96 | <para>Install the package:</para>
|
---|
| 97 |
|
---|
[3cf8a59] | 98 | <screen><userinput remap="install">make install</userinput></screen>
|
---|
[fcc02767] | 99 |
|
---|
[8e751f7] | 100 | <para>We use the <command>pip3</command> command to
|
---|
[ee16e55] | 101 | install Python 3 programs and modules for all users as
|
---|
[8e751f7] | 102 | <systemitem class='username'>root</systemitem> in several places in this book.
|
---|
| 103 | This conflicts with the Python developers' recommendation: to install packages into a
|
---|
| 104 | virtual environment, or into the home directory of a regular user (by running
|
---|
| 105 | <command>pip3</command> as this user). A multi-line warning
|
---|
| 106 | is triggered whenever <command>pip3</command> is issued by the
|
---|
| 107 | <systemitem class='username'>root</systemitem> user.</para>
|
---|
| 108 |
|
---|
| 109 | <para>The main reason
|
---|
| 110 | for the recommendation is to avoid conflicts with the system's
|
---|
| 111 | package manager (<command>dpkg</command>, for example). LFS does not
|
---|
| 112 | have a system-wide package manager, so this is not a problem. Also,
|
---|
| 113 | <command>pip3</command> will check for a new version of
|
---|
| 114 | itself whenever it's run. Since domain name resolution is not yet configured
|
---|
| 115 | in the LFS chroot environment, <command>pip3</command> cannot check
|
---|
| 116 | for a new version of itself, and will
|
---|
| 117 | produce a warning. </para>
|
---|
| 118 |
|
---|
| 119 | <para>After we boot the LFS system and set up a network connection,
|
---|
| 120 | a different warning will be issued, telling the user to update <command>pip3</command>
|
---|
| 121 | from a pre-built wheel on PyPI (whenever a new version is available). But LFS
|
---|
| 122 | considers <command>pip3</command> to be a part of Python 3, so it should not be
|
---|
| 123 | updated separately. Also, an update from a pre-built wheel would deviate
|
---|
| 124 | from our objective: to build a Linux system from source code. So the
|
---|
| 125 | warning about a new version of <command>pip3</command> should be ignored as
|
---|
| 126 | well. If you wish, you can suppress all these warnings by running the following
|
---|
| 127 | command, which creates a configuration file:</para>
|
---|
[e953813] | 128 |
|
---|
[2e9e5b4] | 129 | <screen><userinput remap="install">cat > /etc/pip.conf << EOF
|
---|
| 130 | <literal>[global]
|
---|
[3094b8c] | 131 | root-user-action = ignore
|
---|
[2e9e5b4] | 132 | disable-pip-version-check = true</literal>
|
---|
[3094b8c] | 133 | EOF
|
---|
| 134 | </userinput></screen>
|
---|
| 135 | <!--
|
---|
[e953813] | 136 | <screen><userinput remap="install">sed -e '/def warn_if_run_as_root/a\ return' \
|
---|
| 137 | -i /usr/lib/python3.10/site-packages/pip/_internal/cli/req_command.py
|
---|
| 138 | </userinput></screen>
|
---|
[3094b8c] | 139 | -->
|
---|
[720c0bd] | 140 | <important>
|
---|
| 141 | <para>
|
---|
[dd9987c] | 142 | In LFS and BLFS we normally build and install Python modules with the
|
---|
[8e751f7] | 143 | <command>pip3</command> command. Please be sure that the
|
---|
| 144 | <command>pip3 install</command> commands in both books are
|
---|
| 145 | run as the &root; user (unless it's for a Python virtual environment).
|
---|
| 146 | Running <command>pip3 install</command> as a non-&root; user may seem
|
---|
| 147 | to work, but it will cause the installed module to be inaccessible
|
---|
[dd9987c] | 148 | by other users.
|
---|
[720c0bd] | 149 | </para>
|
---|
[dd9987c] | 150 |
|
---|
[720c0bd] | 151 | <para>
|
---|
[dd9987c] | 152 | <command>pip3 install</command> will not reinstall an already installed
|
---|
[8e751f7] | 153 | module automatically. When using the <command>pip3 install</command>
|
---|
[dd9987c] | 154 | command to upgrade a module (for example, from meson-0.61.3 to
|
---|
| 155 | meson-0.62.0), insert the option <parameter>--upgrade</parameter> into
|
---|
[8e751f7] | 156 | the command line. If it's really necessary to downgrade a module, or
|
---|
[af3cf8d] | 157 | reinstall the same version for some reason, insert
|
---|
| 158 | <parameter>--force-reinstall --no-deps</parameter> into the command
|
---|
| 159 | line.
|
---|
[720c0bd] | 160 | </para>
|
---|
| 161 | </important>
|
---|
[e953813] | 162 |
|
---|
[fcc02767] | 163 | <para>If desired, install the preformatted documentation:</para>
|
---|
| 164 |
|
---|
[d672ab7] | 165 | <screen><userinput remap="install">install -v -dm755 /usr/share/doc/python-&python-version;/html
|
---|
[fcc02767] | 166 |
|
---|
| 167 | tar --strip-components=1 \
|
---|
| 168 | --no-same-owner \
|
---|
| 169 | --no-same-permissions \
|
---|
| 170 | -C /usr/share/doc/python-&python-version;/html \
|
---|
| 171 | -xvf ../python-&python-version;-docs-html.tar.bz2</userinput></screen>
|
---|
| 172 |
|
---|
| 173 | <variablelist>
|
---|
| 174 | <title>The meaning of the documentation install commands:</title>
|
---|
| 175 |
|
---|
| 176 | <varlistentry>
|
---|
| 177 | <term><option>--no-same-owner</option> and <option>--no-same-permissions</option></term>
|
---|
| 178 | <listitem>
|
---|
[d672ab7] | 179 | <para>Ensure the installed files have the correct ownership and
|
---|
[8e751f7] | 180 | permissions. Without these options, <application>tar</application>
|
---|
[d672ab7] | 181 | will install the package files with the upstream creator's values.
|
---|
[fcc02767] | 182 | </para>
|
---|
| 183 | </listitem>
|
---|
| 184 | </varlistentry>
|
---|
| 185 |
|
---|
| 186 | </variablelist>
|
---|
| 187 |
|
---|
| 188 | </sect2>
|
---|
| 189 |
|
---|
| 190 | <sect2 id="contents-python" role="content">
|
---|
| 191 | <title>Contents of Python 3</title>
|
---|
| 192 |
|
---|
| 193 | <segmentedlist>
|
---|
[ab31b97] | 194 | <segtitle>Installed programs</segtitle>
|
---|
| 195 | <segtitle>Installed library</segtitle>
|
---|
| 196 | <segtitle>Installed directories</segtitle>
|
---|
[fcc02767] | 197 |
|
---|
| 198 | <seglistitem>
|
---|
| 199 | <seg>
|
---|
| 200 | 2to3, idle3, pip3, pydoc3, python3, and python3-config
|
---|
| 201 | </seg>
|
---|
| 202 | <seg>
|
---|
| 203 | libpython&python-minor;.so and libpython3.so
|
---|
| 204 | </seg>
|
---|
| 205 | <seg>
|
---|
[d672ab7] | 206 | /usr/include/python&python-minor;,
|
---|
[fcc02767] | 207 | /usr/lib/python3, and
|
---|
| 208 | /usr/share/doc/python-&python-version;
|
---|
| 209 | </seg>
|
---|
| 210 | </seglistitem>
|
---|
| 211 | </segmentedlist>
|
---|
| 212 |
|
---|
| 213 | <variablelist>
|
---|
| 214 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
| 215 | <?dbfo list-presentation="list"?>
|
---|
| 216 | <?dbhtml list-presentation="table"?>
|
---|
| 217 |
|
---|
| 218 | <varlistentry id="python-2to3">
|
---|
| 219 | <term><command>2to3</command></term>
|
---|
| 220 | <listitem>
|
---|
| 221 | <para>
|
---|
| 222 | is a <application>Python</application> program that reads
|
---|
| 223 | <application>Python 2.x</application> source code and applies a
|
---|
[d672ab7] | 224 | series of fixes to transform it into
|
---|
[8d35535] | 225 | valid <application>Python 3.x</application> code
|
---|
[fcc02767] | 226 | </para>
|
---|
| 227 | <indexterm zone="ch-system-Python">
|
---|
| 228 | <primary sortas="b-2to3">2to3</primary>
|
---|
| 229 | </indexterm>
|
---|
| 230 | </listitem>
|
---|
| 231 | </varlistentry>
|
---|
| 232 |
|
---|
| 233 | <varlistentry id="idle3">
|
---|
| 234 | <term><command>idle3</command></term>
|
---|
| 235 | <listitem>
|
---|
| 236 | <para>
|
---|
| 237 | is a wrapper script that opens a <application>Python</application>
|
---|
| 238 | aware GUI editor. For this script to run, you must have installed
|
---|
[8e751f7] | 239 | <application>Tk</application> before Python, so that the Tkinter
|
---|
| 240 | Python module is built.
|
---|
[fcc02767] | 241 | </para>
|
---|
| 242 | <indexterm zone="ch-system-Python">
|
---|
| 243 | <primary sortas="b-idle3">idle3</primary>
|
---|
| 244 | </indexterm>
|
---|
| 245 | </listitem>
|
---|
| 246 | </varlistentry>
|
---|
| 247 |
|
---|
| 248 | <varlistentry id="pip3">
|
---|
| 249 | <term><command>pip3</command></term>
|
---|
| 250 | <listitem>
|
---|
| 251 | <para>
|
---|
| 252 | The package installer for Python. You can use pip to install
|
---|
[8e751f7] | 253 | packages from Python Package Index and other indexes.
|
---|
[fcc02767] | 254 | </para>
|
---|
| 255 | <indexterm zone="ch-system-Python">
|
---|
| 256 | <primary sortas="b-pip3">pip3</primary>
|
---|
| 257 | </indexterm>
|
---|
| 258 | </listitem>
|
---|
| 259 | </varlistentry>
|
---|
| 260 |
|
---|
| 261 | <varlistentry id="pydoc3">
|
---|
| 262 | <term><command>pydoc3</command></term>
|
---|
| 263 | <listitem>
|
---|
| 264 | <para>
|
---|
[8d35535] | 265 | is the <application>Python</application> documentation tool
|
---|
[fcc02767] | 266 | </para>
|
---|
| 267 | <indexterm zone="ch-system-Python">
|
---|
| 268 | <primary sortas="b-pydoc3">pydoc3</primary>
|
---|
| 269 | </indexterm>
|
---|
| 270 | </listitem>
|
---|
| 271 | </varlistentry>
|
---|
| 272 |
|
---|
| 273 | <varlistentry id="python3">
|
---|
| 274 | <term><command>python3</command></term>
|
---|
| 275 | <listitem>
|
---|
| 276 | <para>
|
---|
[8e751f7] | 277 | is the interpreter for Python, an interpreted, interactive,
|
---|
| 278 | object-oriented programming language
|
---|
[fcc02767] | 279 | </para>
|
---|
| 280 | <indexterm zone="ch-system-Python">
|
---|
| 281 | <primary sortas="b-python3">python3</primary>
|
---|
| 282 | </indexterm>
|
---|
| 283 | </listitem>
|
---|
| 284 | </varlistentry>
|
---|
[6a156bab] | 285 |
|
---|
[fcc02767] | 286 | </variablelist>
|
---|
| 287 |
|
---|
| 288 | </sect2>
|
---|
| 289 |
|
---|
| 290 | </sect1>
|
---|
| 291 |
|
---|