The Python 3 package contains the Python development environment.
          It is useful for object-oriented programming, writing scripts,
          prototyping large programs, or developing entire applications.
        
        
          
            
              Approximate build time:
              3.4 SBU
            
            
              Required disk space:
              283 MB
            
           
         
       
      
        
          8.50.1. Installation of Python 3
        
        
          Prepare Python for compilation:
        
        ./configure --prefix=/usr        \
            --enable-shared      \
            --with-system-expat  \
            --with-system-ffi    \
            --enable-optimizations
        
          
            The meaning of the configure options:
          
          
            - 
              --with-system-expat
- 
              
                This switch enables linking against system version of
                Expat.
               
- 
              --with-system-ffi
- 
              
                This switch enables linking against system version of
                libffi.
               
- 
              --enable-optimizations
- 
              
                This switch enables stable, but expensive, optimizations.
               
 
        
          Compile the package:
        
        make
        
          Running the tests at this point is not recommended. The tests are
          known to hang indefinitely in the partial LFS environment. If
          desired, the tests can be rerun at the end of this chapter or when
          Python 3 is reinstalled in BLFS. To run the tests anyway, issue
          make test.
        
        
          Install the package:
        
        make install
        
          In several places we use the pip3 command to install Python 3
          programs and modules for all users as root. This conflicts with the Python developers
          recommendation to install packages into a virtual environment or
          the home directory of a regular user (by running pip3 as this user). To this end,
          a multi-line warning is written when using pip3 as the root user. The main reason of this
          recommendation is for avoiding a conflict with the system package
          manager (dpkg for
          example), but LFS does not have a system-wide package manager so
          this is not a problem. And, pip3 will attempt to check for a
          new version of itself whenever it's run. As domain name resolving
          is not configured yet in LFS chroot environment, it will fail to
          check for a new version and produce a warning. Once we boot the LFS
          system and set up network connection, it will then produce a
          warning telling the user to update it from a pre-built wheel on
          PyPI if any new version is available. But LFS consider pip3 a part of Python 3 so it
          should not be updated separately, and an update from a pre-built
          wheel will deviate from our purpose to build a Linux system from
          source code. So the warning for a new pip3 version should be ignored as
          well. If desired, suppress these warnings by running the following
          commands:
        
        cat > /etc/pip.conf << EOF
[global]
root-user-action = ignore
disable-pip-version-check = true
EOF
        
          ![[Important]](../images/important.png) 
          
            Important
          
          
            In LFS and BLFS we normally build and install Python modules with
            the pip3 command.
            Please take care that the pip3
            install commands in both the books should be run
            as the root user unless it's for
            a Python virtual environment. Running a pip3 install as a
            non-root user may seem to work
            fine, but it will cause the installed module to be inaccessible
            by other users.
          
          
            pip3 install will
            not reinstall an already installed module by default. For using
            the pip3 install
            command to upgrade a module (for example, from meson-0.61.3 to
            meson-0.62.0), insert the option --upgrade into the command line. If
            it's really necessary to downgrade a module or reinstall the same
            version for some reason, insert --force-reinstall --no-deps into
            the command line.
          
         
        
          If desired, install the preformatted documentation:
        
        install -v -dm755 /usr/share/doc/python-3.10.6/html
tar --strip-components=1  \
    --no-same-owner       \
    --no-same-permissions \
    -C /usr/share/doc/python-3.10.6/html \
    -xvf ../python-3.10.6-docs-html.tar.bz2
        
          
            The meaning of the documentation install
            commands:
          
          
            - 
              --no-same-ownerand--no-same-permissions
- 
              
                Ensure the installed files have the correct ownership and
                permissions. Without these options, using tar will install the package files with
                the upstream creator's values.