8000 Add inline tabs on Setup and Building page for commands on different … · python/devguide@6d96e57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d96e57

Browse files
authored
Add inline tabs on Setup and Building page for commands on different systems (#1226)
1 parent 1909f67 commit 6d96e57

File tree

1 file changed

+104
-98
lines changed

1 file changed

+104
-98
lines changed

getting-started/setup-building.rst

Lines changed: 104 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
Setup and building
66
==================
77

8+
.. raw:: html
9+
10+
<script>
11+
document.addEventListener('DOMContentLoaded', function() {
12+
activateTab(getOS());
13+
});
14+
</script>
15+
816
.. highlight:: console
917

1018
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.
257265
258266
$ ./configure --enable-optimizations --with-lto
259267
260-
261268
.. _windows-compiling:
262269

263270
Windows
@@ -339,156 +346,155 @@ and how to build.
339346

340347

341348
.. _build-dependencies:
349+
.. _deps-on-linux:
350+
.. _macOS and OS X:
351+
.. _macOS:
342352

343353
Install dependencies
344354
====================
345355

346356
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`.
349358

350-
.. _deps-on-linux:
359+
.. tab:: Linux
351360

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.
354366

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::
360368

361-
On **Fedora**, **Red Hat Enterprise Linux** and other ``yum`` based systems::
369+
$ sudo yum install yum-utils
370+
$ sudo yum-builddep python3
362371

363-
$ sudo yum install yum-utils
364-
$ sudo yum-builddep python3
372+
On **Fedora** and other ``DNF`` based systems::
365373

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
367376

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.
370379

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::
373384

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
378386

379-
deb-src http://archive.ubuntu.com/ubuntu/ jammy main
387+
Alternatively, uncomment lines with ``deb-src`` using an editor, e.g.::
380388

381-
Alternatively, uncomment lines with ``deb-src`` using an editor, e.g.::
389+
sudo nano /etc/apt/sources.list
382390

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.
384393

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::
387395

388-
Then you should update the packages index::
396+
$ sudo apt-get update
389397

390-
$ sudo apt-get update
398+
Now you can install the build dependencies via ``apt``::
391399

392-
Now you can install the build dependencies via ``apt``::
400+
$ sudo apt-get build-dep python3
401+
$ sudo apt-get install pkg-config
393402

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::
396405

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
399410

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
404411

412+
.. tab:: macOS
405413

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.
408417

409-
macOS
410-
-----
418+
If necessary, run the following::
411419

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
415421

416-
If necessary, run the following::
422+
This will also ensure that the system header files are installed into
423+
``/usr/include``.
417424

418-
$ xcode-select --install
425+
.. _Homebrew: https://brew.sh
419426

420-
This will also ensure that the system header files are installed into
421-
``/usr/include``.
427+
.. _MacPorts: https://www.macports.org
422428

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.
424437

425-
.. _MacPorts: https://www.macports.org
438+
For example, with **Homebrew**, install the dependencies::
426439

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
435441

436-
For example, with **Homebrew**, install the dependencies::
442+
Then, for Python 3.11 and newer, run ``configure``::
437443

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)"
439448

440-
Then, for Python 3.11 and newer, run ``configure``::
449+
Or, for Python 3.8 through 3.10::
441450

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)"
446457

447-
Or, for Python 3.8 through 3.10::
458+
And finally, run ``make``::
448459

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
455461

456-
And finally, run ``make``::
462+
Alternatively, with **MacPorts**::
457463

458-
$ make -s -j2
464+
$ sudo port install pkgconfig openssl xz gdbm tcl tk +quartz
459465

460-
Alternatively, with **MacPorts**::
466+
Then, for Python 3.11 and newer, run ``configure``::
461467

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
463471

464-
Then, for Python 3.11 and newer, run ``configure``::
472+
And finally, run ``make``::
465473

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
469475

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`.
471479

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.
473482

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>`_.
477486

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/
480489

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.
484494

485-
.. _clang: https://clang.llvm.org/
486-
.. _ccache: https://ccache.dev/
495+
.. tab:: Windows
487496

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.
492498

493499

494500
.. _regenerate_configure:

0 commit comments

Comments
 (0)
0