Mac にpyton をインストールしようとしたところ、エラーになってしまったのでその時の対応方法をここにメモします。
エラー
pyenv で python v3.11.4 をインストールしようとしたところ、"ModuleNotFoundError: No module named '_tkinter'"というメッセージが出てインストールが失敗します。
% pyenv install 3.11.4
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.4.tar.xz...
-> https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz
Installing Python-3.11.4...
python-build: use readline from homebrew
python-build: use ncurses from homebrew
python-build: use zlib from xcode sdk
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/{{user}}/.pyenv/versions/3.11.4/lib/python3.11/tkinter/__init__.py", line 38, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_tkinter'
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
Installed Python-3.11.4 to /Users/{{user}}/.pyenv/versions/3.11.4
対処法
Homebrewを使って、python-tkをインストールします。
% brew install python-tk
再度インストールコマンドを実行します。
% pyenv install 3.11.4