見出し画像

【IT】MacOSでのpyenvのアップデート

皆さま
こんにちは

久しぶりに操作端末であるMacBookに導入されている
pythonの仮想環境のpyenvのアップデートをします。

現在の状態を確認します。
少し前のバージョンまでしか表示されません。

$ pyenv install --list
Available versions:
       ・
         ・
  3.10.6
  3.10.7
  3.11.0rc2
  3.11-dev
  3.12-dev
  activepython-2.7
       ・
       ・

brewで入れてますので以下のコマンドでアップデートします。

$ brew upgrade pyenv
==> Upgrading 1 outdated package:
pyenv 2.3.5 -> 2.3.9
==> Fetching pyenv
==> Downloading https://ghcr.io/v2/homebrew/core/pyenv/manifests/2.3.9
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pyenv/blobs/sha256:ad4ff2d4ceee
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Upgrading pyenv
  2.3.5 -> 2.3.9

==> Pouring pyenv--2.3.9.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/pyenv/2.3.9: 979 files, 3.1MB
==> Running `brew cleanup pyenv`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /usr/local/Cellar/pyenv/2.3.5... (943 files, 3MB)

$ pyenv rehash

対応するバージョンが増えたか確認します。
今回の目的だった、3.11の安定版がリストされています。

$ pyenv install --list 
Available versions:
       ・
       ・
   3.10.7
  3.10.8
  3.10.9
  3.11.0
  3.11-dev
  3.11.1
  3.12.0a3
  3.12-dev
       ・
       ・

早速、インストールしますが、以下のエラーとなります。

$ pyenv install 3.11.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.1.tar.xz...
-> https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tar.xz
Installing Python-3.11.1...
python-build: use readline from homebrew

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

Inspect or clean up the working tree at /var/folders/xq/7ftzqcns6kg10jtl3zy5zw0m0000gn/T/python-build.20230108135931.12124
Results logged to /var/folders/xq/7ftzqcns6kg10jtl3zy5zw0m0000gn/T/python-build.20230108135931.12124.log

Last 10 log lines:
checking pkg-config is at least version 0.9.0... yes
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/xq/7ftzqcns6kg10jtl3zy5zw0m0000gn/T/python-build.20230108135931.12124/Python-3.11.1':
configure: error: C compiler cannot create executables
See `config.log' for more details
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

原因は、MacOSのメジャーアップデート時に
インストールに必要なxcodeのCommandLineToolsがクリアされてしまうためです。

$  ll /Library/Developer/CommandLineTools/usr/bin
total 40
drwxr-xr-x  3 root  wheel      96 11 27 21:27 ./
drwxr-xr-x  7 root  wheel     224 11 27 21:27 ../
-rwxr-xr-x  1 root  wheel  167952  1  9  2021 projectInfo*

あらためてCommandLineToolsをインストールします。

$ xcode-select --install

再度、python3.11.1をインストールします。

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

任意のディレクトリで使用できるか確認します。

$ mkdir WORK/test-py311
$ cd WORK/test-py311
$ pyenv local 3.11.1
$ python --version
Python 3.11.1

無事、インストールすることが出来ました。


では

この記事が気に入ったらサポートをしてみませんか?