0
0

More than 3 years have passed since last update.

mac pyenv 環境でtkinterがnomodulenamedになる時の対処法

Posted at

macでtkinterをinstallしても起動せず、いろいろ格闘した末に起動できたので、どうやって解決したかをまとめてみた。

使用していた環境・バージョン

・macos mojave (10.14.6)
・pyenv 2.0.4
・tcl-tk 8.6.11 (bottled)[keg-only]
・python3.9.6

結論

$ brew install tcl-tk,
$ brew install pythonした後に
$ brew install python-tkを入力

症状

python3.9.6を使用。tkinteを使うために以下のようなコマンドを打つとエラーが発生。tkinterはpythonの標準ライブラリのはずなのになぜか起動しない。原因はtcl-tkがパソコンに入っていないことらしいが、最後までイマイチよくわからなかった。

$ python3 main.py
(中略)
Traceback (most recent call last):
(中略)
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter

参考にした記事

こちら質問の一番上の回答より

補足

pythonをアンインストールしてtcl-tkをダウンロード、その後pythonを再ダウンロードと言う記事は山ほどあったが、どれもうまくいかなかった。pathをいじるのもなかなかうまくいかず、結局このコマンド一つで解決できたように思える。

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