This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: build on macOS 11 (beta) does not find system-supplied third-party libraries
Type: Stage: resolved
Components: macOS Versions: Python 3.10, Python 3.9, Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dtrodrigues, lukasz.langa, miss-islington, ned.deily, richiejthomas, ronaldoussoren, seb, sjmulder
Priority: high Keywords: patch

Created on 2020-06-25 15:51 by ned.deily, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23301 merged ronaldoussoren, 2020-11-15 16:31
PR 23455 merged miss-islington, 2020-11-22 05:14
PR 23649 merged ned.deily, 2020-12-05 03:37
PR 23650 merged miss-islington, 2020-12-05 04:02
Messages (19)
msg372379 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-06-25 15:51
When building on macOS 11 (beta), a number of modules that should normally build on macOS fail because the system-supplied third-party libraries are not found.

The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel
_gdbm                 _hashlib              _lzma
_ssl                  ossaudiodev           readline
spwd                  zlib

The list should look like this (with no additional third-party libs supplied from another source like Homebrew or MacPorts):

The necessary bits to build these optional modules were not found:
_gdbm                 _hashlib              _ssl
ossaudiodev           spwd

The problem is due to a change in the 11 beta versus 10.15 or earlier systems: 
"New in macOS Big Sur 11 beta, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache."

This breaks tests in using find_library_file() to determine if a library is present and in what directory it exists. depends on Lib/distutils/ to do the dirty work. A similar problem arose on earlier macOS releases when header files could no longer be installed in the systems /usr/include; had to be taught to look in the SDK being used implicitly or explicitly by the compiler preprocessor.  We could probably do something like that here while trying to avoid changes that might break downstream supplements/replacements to distutils, for example, setuptools.

There is a workaround: explicitly specify the SDK location to ./configure (you also need to specify the universal archs setting):

./configure \
    --enable-universalsdk=$(xcodebuild -version -sdk macosx Path) \
    --with-universal-archs=intel-64 \
msg372415 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-06-26 08:27
These build for me (master branch), because the support for .tbd files in the macOS SDK still works.

The ones that don't build for me:

- Bits not found: _gdbm, _hashlib, _ssl, ossaudiodev, spwd
- Failed to build: _ctypes, _decimal, _lzma

This was with a "Universal 2" build (which explains _ctypes) and without 3party libraries (which explains _gdbm, _ssl and _lzma).  ossaudiodev and spwd are not supported on macOS even on older versions of the OS.

I can get _decimal to build with a trivial patch to Modules/_decimal/ (I'll create a PR later today). The PR will obviously be untested w.r.t. actually supporting ARM64.
msg372416 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-06-26 09:21
I should have specified that the failures I saw were just with the default intel-64 arch on the beta.

After thinking about it a bit and reviewing the code, I think the best approach is to handle this in as part of the compiler flags customization.  What's been happening over the years is that Apple has been deprecating and then removing system header files and system library files on running systems and instead forcing the use of an SDK to build with for both. That's fine but, to continue to support a range of systems, we should be able to handle the various default configurations when the user does not explicitly specify a particular SDK to use. The Apple compiler chain does the right thing under the covers so that C compilations just work.'s macosx_sdk_root() now has initialization code to discover the path to the system header files that the compiler is using; it calls the compiler with -v on a dummy program and then scans the compiler output for the include paths searched until it finds either /usr/include or a path ending in .sdk/usr/include. (It's a bit of a hack but a fairly widely-used hack that works with both clang and gcc, at least, and for the Apple-supplied compilers, takes into account the dynamic specification of SDK via xcrun.)

I think the thing to do is move that sdk path detection into _osx_support and then, at the end of other customization steps, if there isn't already a valid -isysroot provided by the user (either through ./configure or CFLAGS et al, add a -isysroot for the discovered default SDK path (or /) into the appropriate customized compiler and linker flags. It would also provide a function to return the SDK path for (the equivalent of the current macosx_sdk_root()) and others to use. and Distutils should then do the right things for both header and library file paths on any configuration (whether header files are installed or not and whether lib files are installed or not, Command Line Tools or Xcode) and, with luck, any other Distutils replacements that also use _osx_support will also do the right thing.

I had contemplated removing _osx_support at some point in the future but, now with the return of universal files, I'm glad we didn't.
msg372417 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-06-26 09:39
I see, and (as expected) get the same output when I build like that.

I agree that we should teach _osx_support about this. I guess we should add a function that returns the SDK root, which can then be used in distutils (and setuptools, ...) instead of looking for -isysroot in CFLAGS.  The new function can than look for the default SDK when there is no sysroot flag.

For 3.10 we should look into cleaning up, it contains some logic that is no longer valid or necessary (such as looking for the architectures supported by /usr/lib/libSystem.dylib).  We should also avoid adding "-isysroot" to the CFLAGS/LDFLAGS to avoid problems when building on user machines that might have a different version of Xcode.
msg380556 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-11-08 17:17
So close...

the problem we're running into is that "-isysroot" is only added for universal builds, not for regular builds. Furthermore unixccompiler doesn't know that is should always look in the SDK and not in the regular location (for system locations). 

I guess we should switch to:
- Never add -isysroot to CFLAGS (change to configure)
- Teach _osx_support about locating the default sdk root, both for Xcode and "command line tools" (_osx_support.default_sdk_root())
- Use that new function in and unixccompiler.

The first item might affect older systems where Xcode shipped with 2 SDKs (current and previous OS version). 

Is that something we can back port to 3.8 and 3.9? 

A less clean, but smaller, change is to teach the configure script to always add -isysroot on macOS, not just when doing a universal build.
msg380811 - (view) Author: Sijmen J. Mulder (sjmulder) * Date: 2020-11-12 09:57
With './configure; make' of master on macOS 11 on Apple Silicon I get the library detection failure. The quick and easy fix was to amend inc_dirs and lib_dirs in

         if MACOS:
+            sysroot = macosx_sdk_root()
+            self.inc_dirs.append(sysroot + '/usr/include')
+            self.lib_dirs.append(sysroot + '/usr/lib')

Interestingly the lzma library is found, but the module fails because it cannot find lzma.h, which does indeed appear to be missing in the SDK.
msg381589 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-11-22 05:14
New changeset 404a719b5127602c1a948f8e189ab61cd3f147d8 by Ronald Oussoren in branch 'master':
bpo-41116: Ensure system supplied libraries are found on macOS 11 (GH-23301)
msg381598 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-11-22 06:35
New changeset 0aab3522b259c40abf1f070c71aa7b914c1239b5 by Miss Islington (bot) in branch '3.9':
bpo-41116: Ensure system supplied libraries are found on macOS 11 (GH-23301) (GH-23455)
msg382553 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-12-05 04:02
New changeset 29afab6c5f656f07ac85c9b2cf089631b2557a11 by Ned Deily in branch 'master':
bpo-41116: Fix test for macOS Tcl/Tk frameworks (GH-23649)
msg382554 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-12-05 04:27
New changeset 06002b3f0d4570424feef37103c7e9b7d16bd63d by Miss Islington (bot) in branch '3.9':
[3.9] bpo-41116: Fix test for macOS Tcl/Tk frameworks (GH-23649) (GH-23650)
msg384679 - (view) Author: seb (seb) Date: 2021-01-08 16:39
I am running macOS Big Sur Version 11.1 on Silicon and still get the error about the missing lzma.h file. I can confirm that I use the latest Python 3.9.1 version which includes the patches of this issue.

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I./Include -I. -I/usr/local/include -I/Users/dev/Downloads/Python-3.9.1/Include -I/Users/dev/Downloads/Python-3.9.1 -c /Users/dev/Downloads/Python-3.9.1/Modules/_lzmamodule.c -o build/temp.macosx-11.1-arm64-3.9/Users/dev/Downloads/Python-3.9.1/Modules/_lzmamodule.o
/Users/dev/Downloads/Python-3.9.1/Modules/_lzmamodule.c:16:10: fatal error: 'lzma.h' file not found
#include <lzma.h>

Is this supposed to be still the case? Thank you!
msg384680 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-01-08 16:43
> I am running macOS Big Sur Version 11.1 on Silicon and still get the error about the missing lzma.h file.

Unfortunately, Apple does not include the XZ library with macOS so, to build that module, you will need to supply a copy from another source, either build it yourself or from a third-party library provider like Homebrew or MacPorts.  The Python Developer's Guid has some suggestions:
msg384846 - (view) Author: seb (seb) Date: 2021-01-11 16:37
Thanks for the help! I tried the instructions, without success. I installed xz through homebrew (which needs to be installed on Silicon under /opt/homebrew). I can confirm the existance of: /opt/homebrew/Cellar/xz/5.2.5/include/lzma.h

I used CPPFLAGS and also modified the system_include_dirs variable in the file, in both cases lzma.h seems to be ignored.

> system_include_dirs = ['opt/homebrew/include', '/opt/homebrew/Cellar/xz/5.2.5/include']

Am I missing something obvious here? Thanks!
msg384884 - (view) Author: Dustin Rodrigues (dtrodrigues) * Date: 2021-01-12 04:49
If your 'brew --prefix' is /opt/homebrew, then setting

CFLAGS="-I/opt/homebrew/include" CPPFLAGS="-I/opt/homebrew/include" LDFLAGS="-L/opt/homebrew/lib"

when running ./configure appears to be sufficient to build the interpreter with lzma support once you've already done 'brew install xz'.
msg384961 - (view) Author: seb (seb) Date: 2021-01-12 16:29
I tried that before, also with your command, without success. I saw that the CFLAGS includes weren't forwarded to the compiler - I don't know if that is only an issue here on my system. So instead I modified the and added the directory manually. It now works. Thanks for your help!!
msg386895 - (view) Author: Richie Thomas (richiejthomas) Date: 2021-02-13 00:46
Hello, can you give me a few more details around the workaround for this. I am using pyenv to install 3.9.1 and not sure how I would include the xz installed using homebrew. Where do I find the or configure command? Thanks for the help!
msg386901 - (view) Author: Dustin Rodrigues (dtrodrigues) * Date: 2021-02-13 04:11
You'll probably need to contact the pyenv project ( if the following doesn't work for you. However, doing something like 

CFLAGS="-I$(brew --prefix)/include" CPPFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" pyenv install 3.9.1

is working for me to use the lzma module if you already have xz installed with Homebrew.
msg386902 - (view) Author: Richie Thomas (richiejthomas) Date: 2021-02-13 04:20
That works for me. Thank you!

On Fri, Feb 12, 2021 at 11:12 PM Dustin Rodrigues <>

> Dustin Rodrigues <> added the comment:
> You'll probably need to contact the pyenv project (
> if the following doesn't work for you.
> However, doing something like
> CFLAGS="-I$(brew --prefix)/include" CPPFLAGS="-I$(brew --prefix)/include"
> LDFLAGS="-L$(brew --prefix)/lib" pyenv install 3.9.1
> is working for me to use the lzma module if you already have xz installed
> with Homebrew.
> ----------
> _______________________________________
> Python tracker <>
> <>
> _______________________________________
msg392679 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-05-02 09:19
New changeset b29d0a5a7811418c0a1082ca188fd4850185e290 by Ned Deily in branch '3.8':
[3.8] bpo-41100: Support macOS 11 Big Sur and Apple Silicon Macs (#25806)
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85288
2021-05-02 09:38:07ned.deilysetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: - Python 3.7
2021-05-02 09:19:05lukasz.langasetnosy: + lukasz.langa
messages: + msg392679
2021-02-13 04:20:57richiejthomassetmessages: + msg386902
2021-02-13 04:11:38dtrodriguessetmessages: + msg386901
2021-02-13 00:46:36richiejthomassetnosy: + richiejthomas
messages: + msg386895
2021-01-12 16:29:33sebsetmessages: + msg384961
2021-01-12 04:49:30dtrodriguessetnosy: + dtrodrigues
messages: + msg384884
2021-01-11 16:37:33sebsetmessages: + msg384846
2021-01-08 16:43:53ned.deilysetmessages: + msg384680
2021-01-08 16:39:38sebsetnosy: + seb
messages: + msg384679
2020-12-05 04:27:20ned.deilysetmessages: + msg382554
2020-12-05 04:02:26miss-islingtonsetpull_requests: + pull_request22518
2020-12-05 04:02:19ned.deilysetmessages: + msg382553
2020-12-05 03:37:33ned.deilysetpull_requests: + pull_request22517
2020-11-22 06:35:45ned.deilysetmessages: + msg381598
2020-11-22 05:14:38miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request22346
2020-11-22 05:14:30ned.deilysetmessages: + msg381589
2020-11-15 16:31:49ronaldoussorensetkeywords: + patch
stage: patch review
pull_requests: + pull_request22192
2020-11-12 09:57:44sjmuldersetnosy: + sjmulder
messages: + msg380811
2020-11-08 17:17:53ronaldoussorensetmessages: + msg380556
2020-06-26 09:39:07ronaldoussorensetmessages: + msg372417
2020-06-26 09:21:10ned.deilysetmessages: + msg372416
2020-06-26 08:27:11ronaldoussorensetmessages: + msg372415
2020-06-25 15:51:04ned.deilycreate