2025/03/11 現在、新しい Mac に pyenv 経由で Python をインストールしようとすると
Downloading Python-3.12.7.tar.xz... -> https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tar.xz Installing Python-3.12.7... python-build: use readline from homebrew python-build: use zlib from xcode sdk Traceback (most recent call last): File "<string>", line 1, in <module> File "/Users/<あなたの名前>/.pyenv/versions/3.12.7/lib/python3.12/lzma.py", line 27, in <module> from _lzma import * ModuleNotFoundError: No module named '_lzma' WARNING: The Python lzma extension was not compiled. Missing the lzma lib? Installed Python-3.12.7 to /Users/<あなたの名前>/.pyenv/versions/3.12.7
というエラーが起きます。ただし、pyenv は Homebrew でインストールしているとします。これを回避するには、pyenv で Python をインストールする前に
brew install xz
とします。
==> Downloading https://formulae.brew.sh/api/formula.jws.json ==> Downloading https://formulae.brew.sh/api/cask.jws.json ==> Downloading https://ghcr.io/v2/homebrew/core/xz/manifests/5.6.4 ######################################################################### 100.0% ==> Fetching xz ==> Downloading https://ghcr.io/v2/homebrew/core/xz/blobs/sha256:b49f3559f9425b0 ######################################################################### 100.0% ==> Pouring xz--5.6.4.arm64_sequoia.bottle.tar.gz 🍺 /opt/homebrew/Cellar/xz/5.6.4: 96 files, 2.0MB ==> Running `brew cleanup xz`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).