LoginSignup
2
4

More than 1 year has passed since last update.

Mac上のpyenvでインストールできない

Last updated at Posted at 2022-07-17

Mac上で以前にpyenvでインストールできていたのに、久しぶりに新しいバージョンにしようとしたら、インストールできず、解決に至る経緯などを記載しておきます。

目標:Python 3.9.13のコンパイル環境取得

結論:Xcodeの設定で解決

まずは、現状を確認

私のMac環境:

  • MacBook Pro (13-inch, 2016, Four Thunderbolt 3 Ports)
  • MacOS Monterey バージョン 12.4(21F79)

pyenvなどのバージョン:

$ pyenv -v
pyenv 1.2.2

$ python --version
Python 3.7.6

$ pyenv version
3.7.6

$ pyenv versions
  system
* 3.7.6 (set by /Users/xxx/.pyenv/version)
  3.8.1

当時は、3.8系に使用したいパッケージが対応しておらず、その確認のためにインストールしました。

では、環境を更新しつつ、3.9.13をインストール!

この状況で「pyenv install --list」を実行しても古いバージョンのPythonしか出てこないので、pyenvをバージョンアップ!!

$ brew install pyenv

$ pyenv -v
pyenv 2.3.2

これで「pyenv install --list」の実行後のリストに「3.9.13」が表示され、いざインストール!

$ pyenv install 3.9.13
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.13.tar.xz...
-> https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tar.xz
Installing Python-3.9.13...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.4 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/jv/grgyjlls10n_95rvp45l_33m0000gn/T/python-build.20220717113613.13721
Results logged to /var/folders/jv/grgyjlls10n_95rvp45l_33m0000gn/T/python-build.20220717113613.13721.log

Last 10 log lines:
checking for python3.9... python3.9
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "darwin"
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/jv/grgyjlls10n_95rvp45l_33m0000gn/T/python-build.20220717113613.13721/Python-3.9.13':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.

ネット検索して、pyenvを再インストール(reinstall)や、pyenvをアンインストール後にインストールし直すなどがあり、いくつ試しても上記のエラーは変わらない。

$ xcode-select --install

$ softwareupdate --list

$ LDFLAGS="-L$(xcrun --show-sdk-path)/usr/lib" pyenv install 3.9.13

で・・・との記載も試しましたが、変化なし。
元々C言語のコンパイラが問題なんだとは想定していたのですが、
ネット上の情報を元にいろいろと試しても変化がない。
さらに、いろいろと見させていただいていると、Xcodeの設定かな?と思い当たり、

Xcodeを起動

  1. 上のメニュー「Xcode」→ 「Preferences...」を選択
  2. 表示されたPreferencesの上の「Locations」を選択
  3. 「Command Line Tools:」の右側が空欄だったので、クリックするだけで「Xcode 13.4.1(13F100)」が設定される(環境変更によるパスワード入力アリ」)

その後は、

$ pyenv install 3.9.13
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.13.tar.xz...
-> https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tar.xz
Installing Python-3.9.13...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.13 to /Users/tachi/.pyenv/versions/3.9.13

$ pyenv versions
  system
* 3.7.6 (set by /Users/xxx/.pyenv/version)
  3.8.1
  3.9.13

と、ようやくインストール完了!
では、バージョンんを変更します。

$ python --version 
Python 3.7.6

$ pyenv version 
3.7.6 (set by /Users/xxx/.pyenv/version)

$ pyenv global 3.9.13

$ pyenv versions
  system
  3.7.6
  3.8.1
* 3.9.13 (set by /Users/xxx/.pyenv/version)

$ pyenv version
3.9.13 (set by /Users/xxx/.pyenv/version)

$ python --version
Python 3.9.13

無事、環境構築完了!

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4