Error building Python on Mac: _lzma failed to import

I’m trying to recompile latest Python on Mac Big Sur M1 and I get this error:

ld: warning: ignoring file /usr/local/Cellar/xz/5.4.2/lib/liblzma.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
[ERROR] _lzma failed to import: dlopen(/Users/ak/opensource/cpython4/build/lib.macosx-11.5-arm64-3.12-pydebug/_lzma.cpython-312d-darwin.so, 2): Symbol not found: _lzma_alone_decoder
  Referenced from: /Users/ak/opensource/cpython4/build/lib.macosx-11.5-arm64-3.12-pydebug/_lzma.cpython-312d-darwin.so
  Expected in: flat namespace
 in /Users/ak/opensource/cpython4/build/lib.macosx-11.5-arm64-3.12-pydebug/_lzma.cpython-312d-darwin.so
The necessary bits to build these optional modules were not found:
_gdbm                 _hashlib              _ssl
_tkinter
To find the necessary bits, look in configure.ac and config.log.

Following modules built successfully but were removed because they could not be imported:
_lzma

Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer

Checked 111 modules (30 built-in, 74 shared, 2 n/a on macosx-11.5-arm64, 0 disabled, 4 missing, 1 failed on import)

Any help is appreciated!

It looks like you are building on or for an Apple Silicon Mac but the Homebrew installation you have on the machine is for an Intel Mac. If so, note which Homebrew packages you have installed, brew list, then remove Homebrew and reinstall from scratch which should default to an Apple Silicon version, and reinstall those packages.

1 Like

Thanks, that helped! I did uninstall brew previously but I missed that Cellar dir was left behind. Once I removed it, the build worked.