17db96d56Sopenharmony_ciBuilding a Python Mac OS X distribution 27db96d56Sopenharmony_ci======================================= 37db96d56Sopenharmony_ci 47db96d56Sopenharmony_ciThe ``build-install.py`` script creates Python distributions, including 57db96d56Sopenharmony_cicertain third-party libraries as necessary. It builds a complete 67db96d56Sopenharmony_ciframework-based Python out-of-tree, installs it in a funny place with 77db96d56Sopenharmony_ci$DESTROOT, massages that installation to remove .pyc files and such, creates 87db96d56Sopenharmony_cian Installer package from the installation plus other files in ``resources`` 97db96d56Sopenharmony_ciand ``scripts`` and placed that on a ``.dmg`` disk image. 107db96d56Sopenharmony_ciThe installer package built on the dmg is a macOS bundle format installer 117db96d56Sopenharmony_cipackage. This format is deprecated and is no longer supported by modern 127db96d56Sopenharmony_cimacOS systems; it is usable on macOS 10.6 and earlier systems. 137db96d56Sopenharmony_ciTo be usable on newer versions of macOS, the bits in the bundle package 147db96d56Sopenharmony_cimust be assembled in a macOS flat installer package, using current 157db96d56Sopenharmony_civersions of the pkgbuild and productbuild utilities. To pass macoS 167db96d56Sopenharmony_ciGatekeeper download quarantine, the final package must be signed 177db96d56Sopenharmony_ciwith a valid Apple Developer ID certificate using productsign. 187db96d56Sopenharmony_ciStarting with macOS 10.15 Catalina, Gatekeeper now also requires 197db96d56Sopenharmony_cithat installer packages are submitted to and pass Apple's automated 207db96d56Sopenharmony_cinotarization service using the altool command. To pass notarization, 217db96d56Sopenharmony_cithe binaries included in the package must be built with at least 227db96d56Sopenharmony_cithe macOS 10.9 SDK, must now be signed with the codesign utility, 237db96d56Sopenharmony_ciand executables must opt in to the hardened run time option with 247db96d56Sopenharmony_ciany necessary entitlements. Details of these processes are 257db96d56Sopenharmony_ciavailable in the on-line Apple Developer Documentation and man pages. 267db96d56Sopenharmony_ci 277db96d56Sopenharmony_ciA goal of PSF-provided (python.org) Python binaries for macOS is to 287db96d56Sopenharmony_cisupport a wide-range of operating system releases with one set of 297db96d56Sopenharmony_cibinaries. Currently, the oldest release supported by python.org 307db96d56Sopenharmony_cibinaries is macOS 10.9; it is still possible to build Python and 317db96d56Sopenharmony_ciPython installers on older versions of macOS but we not regularly 327db96d56Sopenharmony_citest on those systems nor provide binaries for them. 337db96d56Sopenharmony_ci 347db96d56Sopenharmony_ciPrior to Python 3.9.1, no Python releases supported building on a 357db96d56Sopenharmony_cinewer version of macOS that will run on older versions 367db96d56Sopenharmony_ciby setting MACOSX_DEPLOYMENT_TARGET. This is because the various 377db96d56Sopenharmony_ciPython C modules did not yet support runtime testing of macOS 387db96d56Sopenharmony_cifeature availability (for example, by using macOS AvailabilityMacros.h 397db96d56Sopenharmony_ciand weak-linking). To build a Python that is to be used on a 407db96d56Sopenharmony_cirange of macOS releases, it was necessary to always build on the 417db96d56Sopenharmony_cioldest release to be supported; the necessary shared libraries for 427db96d56Sopenharmony_cithat release will normally also be available on later systems, 437db96d56Sopenharmony_ciwith the occasional exception such as the removal of 32-bit 447db96d56Sopenharmony_cilibraries in macOS 10.15. For 3.9.x and recent earlier systems, 457db96d56Sopenharmony_ciPSF practice was to provide a "macOS 64-bit Intel installer" variant 467db96d56Sopenharmony_cithat was built on 10.9 that would run on macOS 10.9 and later. 477db96d56Sopenharmony_ci 487db96d56Sopenharmony_ciStarting with 3.9.1, Python fully supports macOS "weaklinking", 497db96d56Sopenharmony_cimeaning it is now possible to build a Python on a current macOS version 507db96d56Sopenharmony_ciwith a deployment target of an earlier macOS system. For 3.9.1 and 517db96d56Sopenharmony_cilater systems, we provide a "macOS 64-bit universal2 installer" 527db96d56Sopenharmony_civariant, currently build on macOS 11 Big Sur with fat binaries 537db96d56Sopenharmony_cinatively supporting both Apple Silicon (arm64) and Intel-64 547db96d56Sopenharmony_ci(x86_64) Macs running macOS 10.9 or later. 557db96d56Sopenharmony_ci 567db96d56Sopenharmony_ciThe legacy "macOS 64-bit Intel installer" variant is expected to 577db96d56Sopenharmony_cibe retired prior to the end of 3.9.x support. 587db96d56Sopenharmony_ci 597db96d56Sopenharmony_cibuild-installer.py requires Apple Developer tools, either from the 607db96d56Sopenharmony_ciCommand Line Tools package or from a full Xcode installation. 617db96d56Sopenharmony_ciYou should use the most recent version of either for the operating 627db96d56Sopenharmony_cisystem version in use. (One notable exception: on macOS 10.6, 637db96d56Sopenharmony_ciSnow Leopard, use Xcode 3, not Xcode 4 which was released later 647db96d56Sopenharmony_ciin the 10.6 support cycle.) build-installer.py also must be run 657db96d56Sopenharmony_ciwith recent versions of Python 3.x or 2.7. On older systems, 667db96d56Sopenharmony_cidue to changes in TLS practices, it may be easier to manually 677db96d56Sopenharmony_cidownload and cache third-party source distributions used by 687db96d56Sopenharmony_cibuild-installer.py rather than have it attempt to automatically 697db96d56Sopenharmony_cidownload them. 707db96d56Sopenharmony_ci 717db96d56Sopenharmony_ci1. universal2, arm64 and x86_64, for OS X 10.9 (and later):: 727db96d56Sopenharmony_ci 737db96d56Sopenharmony_ci /path/to/bootstrap/python3 build-installer.py \ 747db96d56Sopenharmony_ci --universal-archs=universal2 \ 757db96d56Sopenharmony_ci --dep-target=10.9 767db96d56Sopenharmony_ci 777db96d56Sopenharmony_ci - builds the following third-party libraries 787db96d56Sopenharmony_ci 797db96d56Sopenharmony_ci * OpenSSL 1.1.1 807db96d56Sopenharmony_ci * Tcl/Tk 8.6 817db96d56Sopenharmony_ci * NCurses 827db96d56Sopenharmony_ci * SQLite 837db96d56Sopenharmony_ci * XZ 847db96d56Sopenharmony_ci * libffi 857db96d56Sopenharmony_ci 867db96d56Sopenharmony_ci - uses system-supplied versions of third-party libraries 877db96d56Sopenharmony_ci 887db96d56Sopenharmony_ci * readline module links with Apple BSD editline (libedit) 897db96d56Sopenharmony_ci * zlib 907db96d56Sopenharmony_ci * bz2 917db96d56Sopenharmony_ci 927db96d56Sopenharmony_ci - recommended build environment: 937db96d56Sopenharmony_ci 947db96d56Sopenharmony_ci * Mac OS X 11 or later 957db96d56Sopenharmony_ci * Xcode Command Line Tools 12.5 or later 967db96d56Sopenharmony_ci * current default macOS SDK 977db96d56Sopenharmony_ci * ``MACOSX_DEPLOYMENT_TARGET=10.9`` 987db96d56Sopenharmony_ci * Apple ``clang`` 997db96d56Sopenharmony_ci 1007db96d56Sopenharmony_ci2. legacy Intel 64-bit, x86_64, for OS X 10.9 (and later):: 1017db96d56Sopenharmony_ci 1027db96d56Sopenharmony_ci /path/to/bootstrap/python3 build-installer.py \ 1037db96d56Sopenharmony_ci --universal-archs=intel-64 \ 1047db96d56Sopenharmony_ci --dep-target=10.9 1057db96d56Sopenharmony_ci 1067db96d56Sopenharmony_ci - builds the following third-party libraries 1077db96d56Sopenharmony_ci 1087db96d56Sopenharmony_ci * OpenSSL 1.1.1 1097db96d56Sopenharmony_ci * Tcl/Tk 8.6 1107db96d56Sopenharmony_ci * NCurses 1117db96d56Sopenharmony_ci * SQLite 1127db96d56Sopenharmony_ci * XZ 1137db96d56Sopenharmony_ci * libffi 1147db96d56Sopenharmony_ci 1157db96d56Sopenharmony_ci - uses system-supplied versions of third-party libraries 1167db96d56Sopenharmony_ci 1177db96d56Sopenharmony_ci * readline module links with Apple BSD editline (libedit) 1187db96d56Sopenharmony_ci * zlib 1197db96d56Sopenharmony_ci * bz2 1207db96d56Sopenharmony_ci 1217db96d56Sopenharmony_ci - recommended build environment: 1227db96d56Sopenharmony_ci 1237db96d56Sopenharmony_ci * Mac OS X 10.9.5 1247db96d56Sopenharmony_ci * Xcode Command Line Tools 6.2 1257db96d56Sopenharmony_ci * ``MacOSX10.9`` SDK 1267db96d56Sopenharmony_ci * ``MACOSX_DEPLOYMENT_TARGET=10.9`` 1277db96d56Sopenharmony_ci * Apple ``clang`` 1287db96d56Sopenharmony_ci 1297db96d56Sopenharmony_ci 1307db96d56Sopenharmony_ciGeneral Prerequisites 1317db96d56Sopenharmony_ci--------------------- 1327db96d56Sopenharmony_ci 1337db96d56Sopenharmony_ci* No Fink (in ``/sw``) or MacPorts (in ``/opt/local``) or Homebrew or 1347db96d56Sopenharmony_ci other local libraries or utilities (in ``/usr/local``) as they could 1357db96d56Sopenharmony_ci interfere with the build. 1367db96d56Sopenharmony_ci 1377db96d56Sopenharmony_ci* It is safest to start each variant build with an empty source directory 1387db96d56Sopenharmony_ci populated with a fresh copy of the untarred source or a source repo. 1397db96d56Sopenharmony_ci 1407db96d56Sopenharmony_ci* It is recommended that you remove any existing installed version of the 1417db96d56Sopenharmony_ci Python being built:: 1427db96d56Sopenharmony_ci 1437db96d56Sopenharmony_ci sudo rm -rf /Library/Frameworks/Python.framework/Versions/n.n 1447db96d56Sopenharmony_ci 145