Build#
This page considers details on building python from source.
Note: The examples in this notebook must be run in the same environment, as they can alter your system’s configuration.
You can download the distribution from the corresponding releases of the official github account.
Check Compile and build section of documentation.
The following cell installs everything needed to build Python, downloads, and extracts the Python version that we’ll use as an example.
apt update &> /dev/null && apt install -y wget gcc make &> /dev/null
[ -d /tmp/installation ] && rm -r /tmp/installation
mkdir /tmp/installation
cd /tmp/installation
wget -q https://github.com/python/cpython/archive/refs/tags/3.8.tar.gz
tar -xzf 3.8.tar.gz
cd cpython-3.8
The resulting Python build may or may not include specific features. This is typically determined during the ./configure
step using CLI parameters that start with the word with
.
All available options can be checked by running the ./configure --help
command.
The following cell displays parts of the ./configure --help
command, as the full output is too lengthy.
./configure --help | grep with | head -n 20
--disable-option-checking ignore unrecognized --enable/--with options
--enable-ipv6 Enable ipv6 (with ipv4) support
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-universal-archs=ARCH
--with-framework-name=FRAMEWORK
with --enable-framework
--with-cxx-main=<compiler>
compile main() and link python executable with C++
--with-suffix=.exe set executable suffix
--with-pydebug build with Py_DEBUG defined
--with-trace-refs enable tracing references for debugging purpose
--with-assertions build with C assertions enabled
--with-lto Enable Link Time Optimization in any build. Disabled
--with-hash-algorithm=[fnv|siphash24]
--with-address-sanitizer
--with-memory-sanitizer enable MemorySanitizer (msan)
--with-undefined-behavior-sanitizer
--with-libs='lib1 ...' link against additional libs
--with-system-expat build pyexpat module using an installed expat
Builtin packages#
There is a set of python packages that can only be installed by building python.
Some packages can only be included in the Python build if the corresponding tools are installed on the system. The following table lists some of the required utilities.
Python Module |
Purpose |
Required System Package(s) |
---|---|---|
|
bzip2 compression |
|
|
LZMA compression |
|
|
SSL/TLS support |
|
|
SQLite support |
|
|
C foreign function interface |
|
|
GUI support with Tk |
|
|
Command line editing (e.g., |
|
|
GNU dbm database |
|
|
Unix ndbm database |
|
|
UUID support |
|
|
Compression support |
|
|
Decimal floating point |
|
|
SQLite bindings |
|
|
SSL module |
|
|
Hashing (SHA, MD5) |
|
|
GUI support |
|
|
Terminal handling |
|
|
bzip2 support |
|
|
xz compression |
|
|
Terminal and system call interfaces |
Usually always built on Unix |
Here are the parameters required for package installation, the absence of which caused some problems in my practice:
--with-ensurepip
: garantees that python will have theensurepip
package, which installes pip in python and possble virtual environments.--with-ssl-default-sites=openssl
to include the ssl module in the build.