LoginSignup
1
0

【Python】ModuleNotFoundError: No module named '_tkinter'

Last updated at Posted at 2023-12-30

MacでTkinterを使用する

TkinterはPythonの標準的なGUIライブラリとして広く利用される。またよく知られている通り、MacOSにはPythonがプリインストールされており、実行環境を構築しなくとも、Pythonを利用することができる。

しかし、MacOSでTkinterを使用しようとした場合、以下のようなエラーが発生するケースがある。

ModuleNotFoundError: No module named '_tkinter'

対処法

原因の一つとして、Tkinterがインストールされていない、もしくはそのバージョンがPythonのバージョンと一致していないことが考えられる。その場合、以下のコマンドでPythonのバージョンを確認し、バージョンに合ったtkinterをインストールする必要がある。

ターミナル
$python --version
Python 3.11.5

$brew install python-tk@3.11

ここでは、Pythonのバージョンが3.11のため、homebrewを使用してpython-tk@3.11をインストールしている。
また、homebrewをインストールしていない場合、以下を実行し別途インストールの上、上記を実行する必要がある。

ターミナル
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

参考

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