0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

macOSのpyenvでTkinterが正しく使えるようにビルドする方法

Last updated at Posted at 2025-04-21

macOSのpyenvを使うと、Tkinterが正しく動かないことが多いのです。

正しくインストールするポイントは、次の通り:

  • tcl-tk@8をインストールすること
  • ビルド時の変数にtcl-tk@8へのパスを追加すること

2025/04/21の時点で、下記のようにインストールするとうまくいきました。

1. 依存パッケージをインストール

brew install openssl readline sqlite3 xz zlib
brew install tcl-tk@8  # バージョン9.0に問題があるので @8 を明示

なお、コマンド「brew pin tcl-tk@8」を実行しておくと、tcl-tkのアップグレードを抑止できます。​

2. シェルに追記(例: ~/.zshrc)

export PATH="$(brew --prefix tcl-tk@8)/bin:$PATH"
export CPPFLAGS="-I$(brew --prefix tcl-tk@8)/include"
export LDFLAGS="-L$(brew --prefix tcl-tk@8)/lib"
export PKG_CONFIG_PATH="$(brew --prefix tcl-tk@8)/lib/pkgconfig"

3. Python をビルド

env PYTHON_CONFIGURE_OPTS="--enable-framework" \
    pyenv install 3.9.22

4. 動作確認

pyenv global 3.9.22
python -m tkinter

オプション

Pythonで最も簡単にGUIが作成できるパッケージTkEasyGUIをインストール!

pip install -U TkEasyGUI
python -c "import TkEasyGUI as eg; eg.popup('hi')"

というのも、Python3.9で、TkEasyGUIが動かないと報告があったので、試行錯誤してインストールしました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?