|
5 | 5 | Setup and building |
6 | 6 | ================== |
7 | 7 |
|
| 8 | +.. raw:: html |
| 9 | + |
| 10 | + <script> |
| 11 | + document.addEventListener('DOMContentLoaded', function() { |
| 12 | + activateTab(getOS()); |
| 13 | + }); |
| 14 | + </script> |
| 15 | + |
8 | 16 | .. highlight:: console |
9 | 17 |
|
10 | 18 | These instructions cover how to get a working copy of the source code and a |
@@ -257,7 +265,6 @@ to learn more about these options. |
257 | 265 |
|
258 | 266 | $ ./configure --enable-optimizations --with-lto |
259 | 267 |
|
260 | | -
|
261 | 268 | .. _windows-compiling: |
262 | 269 |
|
263 | 270 | Windows |
@@ -339,156 +346,155 @@ and how to build. |
339 | 346 |
|
340 | 347 |
|
341 | 348 | .. _build-dependencies: |
| 349 | +.. _deps-on-linux: |
| 350 | +.. _macOS and OS X: |
| 351 | +.. _macOS: |
342 | 352 |
|
343 | 353 | Install dependencies |
344 | 354 | ==================== |
345 | 355 |
|
346 | 356 | This section explains how to install additional extensions (e.g. ``zlib``) |
347 | | -on :ref:`Linux <deps-on-linux>` and :ref:`macOS`. On Windows, |
348 | | -extensions are already included and built automatically. |
| 357 | +on :ref:`Linux <deps-on-linux>` and :ref:`macOS`. |
349 | 358 |
|
350 | | -.. _deps-on-linux: |
| 359 | +.. tab:: Linux |
351 | 360 |
|
352 | | -Linux |
353 | | ------ |
| 361 | + For Unix-based systems, we try to use system libraries whenever available. |
| 362 | + This means optional components will only build if the relevant system headers |
| 363 | + are available. The best way to obtain the appropriate headers will vary by |
| 364 | + distribution, but the appropriate commands for some popular distributions |
| 365 | + are below. |
354 | 366 |
|
355 | | -For Unix-based systems, we try to use system libraries whenever available. |
356 | | -This means optional components will only build if the relevant system headers |
357 | | -are available. The best way to obtain the appropriate headers will vary by |
358 | | -distribution, but the appropriate commands for some popular distributions |
359 | | -are below. |
| 367 | + On **Fedora**, **Red Hat Enterprise Linux** and other ``yum`` based systems:: |
360 | 368 |
|
361 | | -On **Fedora**, **Red Hat Enterprise Linux** and other ``yum`` based systems:: |
| 369 | + $ sudo yum install yum-utils |
| 370 | + $ sudo yum-builddep python3 |
362 | 371 |
|
363 | | - $ sudo yum install yum-utils |
364 | | - $ sudo yum-builddep python3 |
| 372 | + On **Fedora** and other ``DNF`` based systems:: |
365 | 373 |
|
366 | | -On **Fedora** and other ``DNF`` based systems:: |
| 374 | + $ sudo dnf install dnf-plugins-core # install this to use 'dnf builddep' |
| 375 | + $ sudo dnf builddep python3 |
367 | 376 |
|
368 | | - $ sudo dnf install dnf-plugins-core # install this to use 'dnf builddep' |
369 | | - $ sudo dnf builddep python3 |
| 377 | + On **Debian**, **Ubuntu**, and other ``apt`` based systems, try to get the |
| 378 | + dependencies for the Python you're working on by using the ``apt`` command. |
370 | 379 |
|
371 | | -On **Debian**, **Ubuntu**, and other ``apt`` based systems, try to get the |
372 | | -dependencies for the Python you're working on by using the ``apt`` command. |
| 380 | + First, make sure you have enabled the source packages in the sources list. |
| 381 | + You can do this by adding the location of the source packages, including |
| 382 | + URL, distribution name and component name, to ``/etc/apt/sources.list``. |
| 383 | + Take Ubuntu 22.04 LTS (Jammy Jellyfish) for example:: |
373 | 384 |
|
374 | | -First, make sure you have enabled the source packages in the sources list. |
375 | | -You can do this by adding the location of the source packages, including |
376 | | -URL, distribution name and component name, to ``/etc/apt/sources.list``. |
377 | | -Take Ubuntu 22.04 LTS (Jammy Jellyfish) for example:: |
| 385 | + deb-src http://archive.ubuntu.com/ubuntu/ jammy main |
378 | 386 |
|
379 | | - deb-src http://archive.ubuntu.com/ubuntu/ jammy main |
| 387 | + Alternatively, uncomment lines with ``deb-src`` using an editor, e.g.:: |
380 | 388 |
|
381 | | -Alternatively, uncomment lines with ``deb-src`` using an editor, e.g.:: |
| 389 | + sudo nano /etc/apt/sources.list |
382 | 390 |
|
383 | | - sudo nano /etc/apt/sources.list |
| 391 | + For other distributions, like Debian, change the URL and names to correspond |
| 392 | + with the specific distribution. |
384 | 393 |
|
385 | | -For other distributions, like Debian, change the URL and names to correspond |
386 | | -with the specific distribution. |
| 394 | + Then you should update the packages index:: |
387 | 395 |
|
388 | | -Then you should update the packages index:: |
| 396 | + $ sudo apt-get update |
389 | 397 |
|
390 | | - $ sudo apt-get update |
| 398 | + Now you can install the build dependencies via ``apt``:: |
391 | 399 |
|
392 | | -Now you can install the build dependencies via ``apt``:: |
| 400 | + $ sudo apt-get build-dep python3 |
| 401 | + $ sudo apt-get install pkg-config |
393 | 402 |
|
394 | | - $ sudo apt-get build-dep python3 |
395 | | - $ sudo apt-get install pkg-config |
| 403 | + If you want to build all optional modules, install the following packages and |
| 404 | + their dependencies:: |
396 | 405 |
|
397 | | -If you want to build all optional modules, install the following packages and |
398 | | -their dependencies:: |
| 406 | + $ sudo apt-get install build-essential gdb lcov pkg-config \ |
| 407 | + libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \ |
| 408 | + libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \ |
| 409 | + lzma lzma-dev tk-dev uuid-dev zlib1g-dev |
399 | 410 |
|
400 | | - $ sudo apt-get install build-essential gdb lcov pkg-config \ |
401 | | - libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \ |
402 | | - libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \ |
403 | | - lzma lzma-dev tk-dev uuid-dev zlib1g-dev |
404 | 411 |
|
| 412 | +.. tab:: macOS |
405 | 413 |
|
406 | | -.. _macOS and OS X: |
407 | | -.. _macOS: |
| 414 | + For **macOS systems** (versions 10.9+), |
| 415 | + the Developer Tools can be downloaded and installed automatically; |
| 416 | + you do not need to download the complete Xcode application. |
408 | 417 |
|
409 | | -macOS |
410 | | ------ |
| 418 | + If necessary, run the following:: |
411 | 419 |
|
412 | | -For **macOS systems** (versions 10.9+), |
413 | | -the Developer Tools can be downloaded and installed automatically; |
414 | | -you do not need to download the complete Xcode application. |
| 420 | + $ xcode-select --install |
415 | 421 |
|
416 | | -If necessary, run the following:: |
| 422 | + This will also ensure that the system header files are installed into |
| 423 | + ``/usr/include``. |
417 | 424 |
|
418 | | - $ xcode-select --install |
| 425 | + .. _Homebrew: https://brew.sh |
419 | 426 |
|
420 | | -This will also ensure that the system header files are installed into |
421 | | -``/usr/include``. |
| 427 | + .. _MacPorts: https://www.macports.org |
422 | 428 |
|
423 | | -.. _Homebrew: https://brew.sh |
| 429 | + Also note that macOS does not include several libraries used by the Python |
| 430 | + standard library, including ``libzma``, so expect to see some extension module |
| 431 | + build failures unless you install local copies of them. As of OS X 10.11, |
| 432 | + Apple no longer provides header files for the deprecated system version of |
| 433 | + OpenSSL which means that you will not be able to build the ``_ssl`` extension. |
| 434 | + One solution is to install these libraries from a third-party package |
| 435 | + manager, like Homebrew_ or MacPorts_, and then add the appropriate paths |
| 436 | + for the header and library files to your ``configure`` command. |
424 | 437 |
|
425 | | -.. _MacPorts: https://www.macports.org |
| 438 | + For example, with **Homebrew**, install the dependencies:: |
426 | 439 |
|
427 | | -Also note that macOS does not include several libraries used by the Python |
428 | | -standard library, including ``libzma``, so expect to see some extension module |
429 | | -build failures unless you install local copies of them. As of OS X 10.11, |
430 | | -Apple no longer provides header files for the deprecated system version of |
431 | | -OpenSSL which means that you will not be able to build the ``_ssl`` extension. |
432 | | -One solution is to install these libraries from a third-party package |
433 | | -manager, like Homebrew_ or MacPorts_, and then add the appropriate paths |
434 | | -for the header and library files to your ``configure`` command. |
| 440 | + $ brew install pkg-config openssl@3.0 xz gdbm tcl-tk |
435 | 441 |
|
436 | | -For example, with **Homebrew**, install the dependencies:: |
| 442 | + Then, for Python 3.11 and newer, run ``configure``:: |
437 | 443 |
|
438 | | - $ brew install pkg-config openssl@3.0 xz gdbm tcl-tk |
| 444 | + $ GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \ |
| 445 | + GDBM_LIBS="-L$(brew --prefix gdbm)/lib -lgdbm" \ |
| 446 | + ./configure --with-pydebug \ |
| 447 | + --with-openssl="$(brew --prefix openssl@3.0)" |
439 | 448 |
|
440 | | -Then, for Python 3.11 and newer, run ``configure``:: |
| 449 | + Or, for Python 3.8 through 3.10:: |
441 | 450 |
|
442 | | - $ GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \ |
443 | | - GDBM_LIBS="-L$(brew --prefix gdbm)/lib -lgdbm" \ |
444 | | - ./configure --with-pydebug \ |
445 | | - --with-openssl="$(brew --prefix openssl@3.0)" |
| 451 | + $ CPPFLAGS="-I$(brew --prefix gdbm)/include -I$(brew --prefix xz)/include" \ |
| 452 | + LDFLAGS="-L$(brew --prefix gdbm)/lib -L$(brew --prefix xz)/lib" \ |
| 453 | + ./configure --with-pydebug \ |
| 454 | + --with-openssl="$(brew --prefix openssl@3.0)" \ |
| 455 | + --with-tcltk-libs="$(pkg-config --libs tcl tk)" \ |
| 456 | + --with-tcltk-includes="$(pkg-config --cflags tcl tk)" |
446 | 457 |
|
447 | | -Or, for Python 3.8 through 3.10:: |
| 458 | + And finally, run ``make``:: |
448 | 459 |
|
449 | | - $ CPPFLAGS="-I$(brew --prefix gdbm)/include -I$(brew --prefix xz)/include" \ |
450 | | - LDFLAGS="-L$(brew --prefix gdbm)/lib -L$(brew --prefix xz)/lib" \ |
451 | | - ./configure --with-pydebug \ |
452 | | - --with-openssl="$(brew --prefix openssl@3.0)" \ |
453 | | - --with-tcltk-libs="$(pkg-config --libs tcl tk)" \ |
454 | | - --with-tcltk-includes="$(pkg-config --cflags tcl tk)" |
| 460 | + $ make -s -j2 |
455 | 461 |
|
456 | | -And finally, run ``make``:: |
| 462 | + Alternatively, with **MacPorts**:: |
457 | 463 |
|
458 | | - $ make -s -j2 |
| 464 | + $ sudo port install pkgconfig openssl xz gdbm tcl tk +quartz |
459 | 465 |
|
460 | | -Alternatively, with **MacPorts**:: |
| 466 | + Then, for Python 3.11 and newer, run ``configure``:: |
461 | 467 |
|
462 | | - $ sudo port install pkgconfig openssl xz gdbm tcl tk +quartz |
| 468 | + $ GDBM_CFLAGS="-I$(dirname $(dirname $(which port)))/include" \ |
| 469 | + GDBM_LIBS="-L$(dirname $(dirname $(which port)))/lib -lgdbm" \ |
| 470 | + ./configure --with-pydebug |
463 | 471 |
|
464 | | -Then, for Python 3.11 and newer, run ``configure``:: |
| 472 | + And finally, run ``make``:: |
465 | 473 |
|
466 | | - $ GDBM_CFLAGS="-I$(dirname $(dirname $(which port)))/include" \ |
467 | | - GDBM_LIBS="-L$(dirname $(dirname $(which port)))/lib -lgdbm" \ |
468 | | - ./configure --with-pydebug |
| 474 | + $ make -s -j2 |
469 | 475 |
|
470 | | -And finally, run ``make``:: |
| 476 | + There will sometimes be optional modules added for a new release which |
| 477 | + won't yet be identified in the OS-level build dependencies. In those cases, |
| 478 | + just ask for assistance in the *Core Development* category on :ref:`help-discourse`. |
471 | 479 |
|
472 | | - $ make -s -j2 |
| 480 | + Explaining how to build optional dependencies on a Unix-based system without |
| 481 | + root access is beyond the scope of this guide. |
473 | 482 |
|
474 | | -There will sometimes be optional modules added for a new release which |
475 | | -won't yet be identified in the OS-level build dependencies. In those cases, |
476 | | -just ask for assistance in the *Core Development* category on :ref:`help-discourse`. |
| 483 | + For more details on various options and considerations for building, refer |
| 484 | + to the `macOS README |
| 485 | + <https://github.com/python/cpython/blob/main/Mac/README.rst>`_. |
477 | 486 |
|
478 | | -Explaining how to build optional dependencies on a Unix-based system without |
479 | | -root access is beyond the scope of this guide. |
| 487 | + .. _clang: https://clang.llvm.org/ |
| 488 | + .. _ccache: https://ccache.dev/ |
480 | 489 |
|
481 | | -For more details on various options and considerations for building, refer |
482 | | -to the `macOS README |
483 | | -<https://github.com/python/cpython/blob/main/Mac/README.rst>`_. |
| 490 | + .. note:: While you need a C compiler to build CPython, you don't need any |
| 491 | + knowledge of the C language to contribute! Vast areas of CPython are |
| 492 | + written completely in Python: as of this writing, CPython contains slightly |
| 493 | + more Python code than C. |
484 | 494 |
|
485 | | -.. _clang: https://clang.llvm.org/ |
486 | | -.. _ccache: https://ccache.dev/ |
| 495 | +.. tab:: Windows |
487 | 496 |
|
488 | | -.. note:: While you need a C compiler to build CPython, you don't need any |
489 | | - knowledge of the C language to contribute! Vast areas of CPython are |
490 | | - written completely in Python: as of this writing, CPython contains slightly |
491 | | - more Python code than C. |
| 497 | + On Windows, extensions are already included and built automatically. |
492 | 498 |
|
493 | 499 |
|
494 | 500 | .. _regenerate_configure: |
|
0 commit comments