Python-2.7.16

#### Beyond Linux® From Scratch (systemd Edition) - Version 9.0

### Chapter 13. Programming

- Prev

  PHP-7.3.8

- Next

  Python-3.7.4

- Up
- Home

# Python-2.7.16

## Introduction to Python 2

The Python 2 package contains the Python development environment. It is useful for object-oriented programming, writing scripts, prototyping large programs or developing entire applications. This version is for backward compatibility with other dependent packages.

### Note

Python2 has been deprecated by the upstream developers. Support for Python2 will be discontinued on January 1st, 2020.

BLFS is attempting to use Python3 as much as possible, but some packages have not been updated to support Python3.

This package is known to build and work properly using an LFS-9.0 platform.

### Package Information

- Download (HTTP): https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tar.xz

- Download MD5 sum: 30157d85a2c0479c09ea2cbe61f2aaf5

- Download size: 12 MB

- Estimated disk space required: 131 MB (add 15 MB for tests)

- Estimated build time: 0.7 SBU (Using parallelism=4; add 6.6 SBU for tests)

### Additional Downloads

Optional HTML Documentation

- Download (HTTP): https://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-html.tar.bz2

### Python 2 Dependencies

#### Optional

BlueZ-5.50 and Valgrind-3.15.0

#### Optional (For Additional Modules)

SQLite-3.29.0 and Tk-8.6.9

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/Python

## Installation of Python 2

### Caution

If updating pip2 with the command pip2 install --upgrade pip, it will remove pip3 and the symlink pip installed in LFS. To restore pip and pip3, run, as the `root` user:

    python3 -m pip install --force pip

Install Python 2 by running the following commands:

    ./configure --prefix=/usr       \
                --enable-shared     \
                --with-system-expat \
                --with-system-ffi   \
                --with-ensurepip=yes \
                --enable-unicode=ucs4 &&
    make

To test the results, issue: make -k test. Three tests fail for unknown reasons.

Now, as the `root` user:

    make install &&
    chmod -v 755 /usr/lib/libpython2.7.so.1.0

Since Python 2 is in maintenance mode, and Python 3 is recommended by upstream for development, you probably do not need to install the documentation. However, if you still want to install documentation for both Python versions, be sure to define the `PYTHONDOCS` variable for the version you want to use, each time you need to consult the documentation. If you have downloaded the preformatted documentation from http://docs.python.org/download.html, install it as the `root` user:

    install -v -dm755 /usr/share/doc/python-2.7.16 &&

    tar --strip-components=1                     \
        --no-same-owner                          \
        --directory /usr/share/doc/python-2.7.16 \
        -xvf ../python-2.7.16-docs-html.tar.bz2 &&

    find /usr/share/doc/python-2.7.16 -type d -exec chmod 0755 {} \; &&
    find /usr/share/doc/python-2.7.16 -type f -exec chmod 0644 {} \;

## Command Explanations

`--with-system-expat`: This switch enables linking against system version of Expat.

`--with-system-ffi`: This switch enables linking against system version of libffi.

`--with-ensurepip=yes` : This switch enables building pip and setuptools packaging programs. setuptools is needed for building some Python modules.

`--enable-unicode=ucs4`: This switch enables 32bit Unicode support in Python.

`--with-dbmliborder=bdb:gdbm:ndbm`: Use this switch if you want to build Python DBM Module against Berkeley DB instead of GDBM.

chmod ...: Fix permissions for libraries to be consistent with other libraries.

## Configuring Python 2

In order for python to find the installed documentation, you must add the following environment variable to individual user's or the system's profile:

    export PYTHONDOCS=/usr/share/doc/python-2.7.16

## Contents

Installed Programs: 2to3, pip2, pydoc, python (symlink), python-config (symlink), python2 (symlink), python2-config (symlink), python2.7, python2.7-config, smtpd.py, and idle
Installed Library: libpython2.7.so
Installed Directories: /usr/{include,lib}/python2.7 and /usr/share/doc/python-2.7.16

### Short Descriptions

2to3 | is a Python program that reads Python 2.x source code and applies a series of fixes to transform it into valid Python 3.x code.
pip2 | is the package manager for Python 2.x. It is used to automate management of Python 2.x modules.
idle | is a wrapper script that opens a Python aware GUI editor. For this script to run, you must have installed Tk before Python so that the Tkinter Python module is built.
pydoc | is the Python documentation tool.
python | is an interpreted, interactive, object-oriented programming language.
python2.7 | is a version-specific name for the python program.
smtpd.py | is an SMTP proxy implemented in Python.

Last updated on 2019-08-16 15:28:01 -0700

- Prev

  PHP-7.3.8

- Next

  Python-3.7.4

- Up
- Home