@@ -104,6 +104,7 @@ affected files as described below.)
104104Patches for the documentation can be made from the same repository; see
105105:ref: `documenting `.
106106
107+
107108.. _compiling :
108109
109110Compile and build
@@ -122,22 +123,161 @@ working only on pure Python code the pydebug build provides several useful
122123checks that one should not skip.
123124
124125
125- .. _ build-dependencies :
126+ .. _ unix-compiling :
126127
127- Build dependencies
128- ------------------
128+ UNIX
129+ ----
129130
130- The core CPython interpreter only needs a C compiler to be built; if
131- you get compile errors with a C89 or C99-compliant compiler, please `open a
132- bug report <https://bugs.python.org> `_.
133- However, some of the extension modules will need development headers
131+ The core CPython interpreter only needs a C compiler to be built,
132+ however, some of the extension modules will need development headers
134133for additional libraries (such as the ``zlib `` library for compression).
135134Depending on what you intend to work on, you might need to install these
136135additional requirements so that the compiled interpreter supports the
137136desired features.
138137
139- UNIX
140- ----
138+ If you want to install these optional dependencies, consult the
139+ :ref: `build-dependencies ` section below.
140+
141+ If you don't need to install them, the basic steps for building Python
142+ for development is to configure it and then compile it.
143+
144+ Configuration is typically:
145+
146+ .. code-block :: bash
147+
148+ ./configure --with-pydebug
149+
150+ More flags are available to ``configure ``, but this is the minimum you should
151+ do to get a pydebug build of CPython.
152+
153+ Once ``configure `` is done, you can then compile CPython with:
154+
155+ .. code-block :: bash
156+
157+ make -s -j2
158+
159+ This will build CPython with only warnings and errors being printed to
160+ stderr and utilize up to 2 CPU cores. If you are using a multi-core machine
161+ with more than 2 cores (or a single-core machine), you can adjust the number
162+ passed into the ``-j `` flag to match the number of cores you have.
163+
164+ At the end of the build you should see a success message, possibly followed
165+ by a list of extension modules that haven't been built because their
166+ dependencies were missing:
167+
168+ .. code-block :: none
169+
170+ Python build finished successfully!
171+ The necessary bits to build these optional modules were not found:
172+ _bz2 _dbm _gdbm
173+ _lzma _sqlite3 _ssl
174+ _tkinter _uuid readline
175+ zlib
176+ To find the necessary bits, look in setup.py in detect_modules()
177+ for the module's name.
178+
179+ If the build failed and you are using a C89 or C99-compliant compiler,
180+ please `open a bug report <https://bugs.python.org >`_.
181+
182+ If you decide to :ref: `build-dependencies `, you will need to re-run both
183+ ``configure `` and ``make ``.
184+
185+ .. _mac-python.exe :
186+
187+ Once CPython is done building you will then have a working build
188+ that can be run in-place; ``./python `` on most machines (and what is used in
189+ all examples), ``./python.exe `` wherever a case-insensitive filesystem is used
190+ (e.g. on OS X by default), in order to avoid conflicts with the ``Python ``
191+ directory. There is normally no need to install your built copy
192+ of Python! The interpreter will realize where it is being run from
193+ and thus use the files found in the working copy. If you are worried
194+ you might accidentally install your working copy build, you can add
195+ ``--prefix=/tmp/python `` to the configuration step. When running from your
196+ working directory, it is best to avoid using the ``--enable-shared `` flag
197+ to ``configure ``; unless you are very careful, you may accidentally run
198+ with code from an older, installed shared Python library rather than from
199+ the interpreter you just built.
200+
201+
202+ Clang
203+ '''''
204+
205+ If you are using clang _ to build CPython, some flags you might want to set to
206+ quiet some standard warnings which are specifically superfluous to CPython are
207+ ``-Wno-unused-value -Wno-empty-body -Qunused-arguments ``. You can set your
208+ ``CFLAGS `` environment variable to these flags when running ``configure ``.
209+
210+ If you are using clang _ with ccache _, turn off the noisy
211+ ``parentheses-equality `` warnings with the ``-Wno-parentheses-equality `` flag.
212+ These warnings are caused by clang not having enough information to detect
213+ that extraneous parentheses in expanded macros are valid, because the
214+ preprocessing is done separately by ccache.
215+
216+ If you are using LLVM 2.8, also use the ``-no-integrated-as `` flag in order to
217+ build the :py:mod: `ctypes ` module (without the flag the rest of CPython will
218+ still build properly).
219+
220+
221+ .. _windows-compiling :
222+
223+ Windows
224+ -------
225+
226+ **Python 3.6 ** and later can use Microsoft Visual Studio 2017. You can download
227+ and use any of the free or paid versions of `Visual Studio 2017 `_.
228+
229+ When installing Visual Studio 2017, select the **Python development ** workload
230+ and the optional **Python native development tools ** component to obtain all of
231+ the necessary build tools. If you do not already have git installed, you can
232+ find git for Windows on the **Individual components ** tab of the installer.
233+
234+ .. note :: If you want to build MSI installers, be aware that the build toolchain
235+ for them has a dependency on the Microsoft .NET Framework Version 3.5 (which
236+ may not be configured on recent versions of Windows, such as Windows 10). If
237+ you are building on a recent Windows version, use the Control Panel (Programs
238+ | Programs and Features | Turn Windows Features on or off) and ensure that the
239+ entry ".NET Framework 3.5 (includes .NET 2.0 and 3.0)" is enabled.
240+
241+ Your first build should use the command line to ensure any external dependencies
242+ are downloaded:
243+
244+ .. code-block :: dosbatch
245+
246+ PCBuild\build.bat
247+
248+ After this build succeeds, you can open the ``PCBuild\pcbuild.sln `` solution in
249+ Visual Studio to continue development.
250+
251+ See the `readme `_ for more details on what other software is necessary and how
252+ to build.
253+
254+ .. note :: **Python 2.7** uses Microsoft Visual Studio 2008, which is most easily
255+ obtained through an MSDN subscription. To use the build files in the
256+ `PCbuild directory `_ you will also need Visual Studio 2010, see the `2.7
257+ readme `_ for more details. If you have VS 2008 but not 2010 you can use the
258+ build files in the `PC/VS9.0 directory `_, see the `VS9 readme `_ for details.
259+
260+ .. _Visual Studio 2017 : https://www.visualstudio.com/
261+ .. _readme : https://github.com/python/cpython/blob/master/PCbuild/readme.txt
262+ .. _PCbuild directory : https://github.com/python/cpython/tree/2.7/PCbuild/
263+ .. _2.7 readme : https://github.com/python/cpython/blob/2.7/PCbuild/readme.txt
264+ .. _PC/VS9.0 directory : https://github.com/python/cpython/tree/2.7/PC/VS9.0/
265+ .. _VS9 readme : https://github.com/python/cpython/blob/2.7/PC/VS9.0/readme.txt
266+
267+
268+ .. _build-dependencies :
269+
270+ Install dependencies
271+ ====================
272+
273+ This section explains how to intall additional extensions (e.g. ``zlib ``)
274+ on :ref: `Linux <deps-on-linux >` and :ref: `macOs/OS X <macOS >`. On Windows,
275+ extensions are already included and built automatically.
276+
277+ .. _deps-on-linux :
278+
279+ Linux
280+ -----
141281
142282For UNIX based systems, we try to use system libraries whenever available.
143283This means optional components will only build if the relevant system headers
@@ -223,48 +363,34 @@ with **Homebrew**::
223363
224364 $ brew install openssl xz
225365
226- and configure python versions >= 3.7::
366+ and `` configure `` Python versions >= 3.7::
227367
228368 ./configure --with-pydebug --with-openssl=$(brew --prefix openssl)
229369
230- or configure python versions < 3.7::
370+ or `` configure `` Python versions < 3.7::
231371
232372 $ CPPFLAGS="-I$(brew --prefix openssl)/include" \
233373 LDFLAGS="-L$(brew --prefix openssl)/lib" \
234374 ./configure --with-pydebug
235375
236- and make::
376+ and `` make `` ::
237377
238378 $ make -s -j2
239379
240380or **MacPorts **::
241381
242382 $ sudo port install pkgconfig openssl xz
243383
244- and configure::
384+ and `` configure `` ::
245385
246386 $ CPPFLAGS="-I/opt/local/include" \
247387 LDFLAGS="-L/opt/local/lib" \
248388 ./configure --with-pydebug
249389
250- and make::
390+ and `` make `` ::
251391
252392 $ make -s -j2
253393
254-
255- This will build CPython with only warnings and errors being printed to
256- stderr and utilize up to 2 CPU cores. If you are using a multi-core machine
257- with more than 2 cores (or a single-core machine), you can adjust the number
258- passed into the ``-j `` flag to match the number of cores you have.
259-
260- Do take note of what modules were **not ** built as stated at the end of your
261- build. More than likely you are missing a dependency for the module(s) that
262- were not built, and so you can install the dependencies and re-run both
263- ``configure `` and ``make `` (if available for your OS).
264- Otherwise the build failed and thus should be fixed (at least with a bug being
265- filed on the `issue tracker `_).
266-
267-
268394There will sometimes be optional modules added for a new release which
269395won't yet be identified in the OS level build dependencies. In those cases,
270396just ask for assistance on the core-mentorship list. If working on bug
@@ -283,126 +409,6 @@ root access is beyond the scope of this guide.
283409 more Python code than C.
284410
285411
286- .. _unix-compiling :
287-
288- UNIX
289- ----
290-
291- The basic steps for building Python for development is to configure it and
292- then compile it.
293-
294- Configuration is typically:
295-
296- .. code-block :: bash
297-
298- ./configure --with-pydebug
299-
300- More flags are available to ``configure ``, but this is the minimum you should
301- do to get a pydebug build of CPython.
302-
303- Once ``configure `` is done, you can then compile CPython with:
304-
305- .. code-block :: bash
306-
307- make -s -j2
308-
309- This will build CPython with only warnings and errors being printed to
310- stderr and utilize up to 2 CPU cores. If you are using a multi-core machine
311- with more than 2 cores (or a single-core machine), you can adjust the number
312- passed into the ``-j `` flag to match the number of cores you have.
313-
314- Do take note of what modules were **not ** built as stated at the end of your
315- build. More than likely you are missing a dependency for the module(s) that
316- were not built, and so you can install the dependencies and re-run both
317- ``configure `` and ``make `` (if available for your OS).
318- Otherwise the build failed and thus should be fixed (at least with a bug being
319- filed on the `issue tracker `_).
320-
321- .. _mac-python.exe :
322-
323- Once CPython is done building you will then have a working build
324- that can be run in-place; ``./python `` on most machines (and what is used in
325- all examples), ``./python.exe `` wherever a case-insensitive filesystem is used
326- (e.g. on OS X by default), in order to avoid conflicts with the ``Python ``
327- directory. There is normally no need to install your built copy
328- of Python! The interpreter will realize where it is being run from
329- and thus use the files found in the working copy. If you are worried
330- you might accidentally install your working copy build, you can add
331- ``--prefix=/tmp/python `` to the configuration step. When running from your
332- working directory, it is best to avoid using the ``--enable-shared `` flag
333- to ``configure ``; unless you are very careful, you may accidentally run
334- with code from an older, installed shared Python library rather than from
335- the interpreter you just built.
336-
337- .. _issue tracker : https://bugs.python.org
338-
339-
340- Clang
341- -----
342-
343- If you are using clang _ to build CPython, some flags you might want to set to
344- quiet some standard warnings which are specifically superfluous to CPython are
345- ``-Wno-unused-value -Wno-empty-body -Qunused-arguments ``. You can set your
346- ``CFLAGS `` environment variable to these flags when running ``configure ``.
347-
348- If you are using clang _ with ccache _, turn off the noisy
349- ``parentheses-equality `` warnings with the ``-Wno-parentheses-equality `` flag.
350- These warnings are caused by clang not having enough information to detect
351- that extraneous parentheses in expanded macros are valid, because the
352- preprocessing is done separately by ccache.
353-
354- If you are using LLVM 2.8, also use the ``-no-integrated-as `` flag in order to
355- build the :py:mod: `ctypes ` module (without the flag the rest of CPython will
356- still build properly).
357-
358-
359- .. _windows-compiling :
360-
361- Windows
362- -------
363-
364- **Python 3.6 ** and later can use Microsoft Visual Studio 2017. You can download
365- and use any of the free or paid versions of `Visual Studio 2017 `_.
366-
367- When installing Visual Studio 2017, select the **Python development ** workload
368- and the optional **Python native development tools ** component to obtain all of
369- the necessary build tools. If you do not already have git installed, you can
370- find git for Windows on the **Individual components ** tab of the installer.
371-
372- .. note :: If you want to build MSI installers, be aware that the build toolchain
373- for them has a dependency on the Microsoft .NET Framework Version 3.5 (which
374- may not be configured on recent versions of Windows, such as Windows 10). If
375- you are building on a recent Windows version, use the Control Panel (Programs
376- | Programs and Features | Turn Windows Features on or off) and ensure that the
377- entry ".NET Framework 3.5 (includes .NET 2.0 and 3.0)" is enabled.
378-
379- Your first build should use the command line to ensure any external dependencies
380- are downloaded:
381-
382- .. code-block :: dosbatch
383-
384- PCBuild\build.bat
385-
386- After this build succeeds, you can open the ``PCBuild\pcbuild.sln `` solution in
387- Visual Studio to continue development.
388-
389- See the `readme `_ for more details on what other software is necessary and how
390- to build.
391-
392- .. note :: **Python 2.7** uses Microsoft Visual Studio 2008, which is most easily
393- obtained through an MSDN subscription. To use the build files in the
394- `PCbuild directory `_ you will also need Visual Studio 2010, see the `2.7
395- readme `_ for more details. If you have VS 2008 but not 2010 you can use the
396- build files in the `PC/VS9.0 directory `_, see the `VS9 readme `_ for details.
397-
398- .. _Visual Studio 2017 : https://www.visualstudio.com/
399- .. _readme : https://github.com/python/cpython/blob/master/PCbuild/readme.txt
400- .. _PCbuild directory : https://github.com/python/cpython/tree/2.7/PCbuild/
401- .. _2.7 readme : https://github.com/python/cpython/blob/2.7/PCbuild/readme.txt
402- .. _PC/VS9.0 directory : https://github.com/python/cpython/tree/2.7/PC/VS9.0/
403- .. _VS9 readme : https://github.com/python/cpython/blob/2.7/PC/VS9.0/readme.txt
404-
405-
406412.. _regenerate_configure :
407413
408414Regenerate ``configure ``
0 commit comments