te-touのブログ

音楽制作・車・プログラミング・旅行・その他考えてる事など、備忘録的なことも含めて個人的なページです。

idleしたら、** IDLE can't import Tkinter. Your Python may not be configured for Tk. **




京都大学のpythonの基礎無料の教科書というのが最近ネットで評判らしいので、やってみようと思いました。
ledge.ai

で、もともと個人的にDJANGOで開発作業はしていたので、anacondaはインストール済みでした。

その上で、上記教科書で「IDLE」を使う。とのことだったので、起動を試みました。
ちなみに、IDLEのことは知りませんでした。

IDLE立ち上げ(python2系)

ます、terminalでidleと打ち込むと白い画面のプロンプトみたいのが立ち上がりました。
しかし、これはpython2系のもののようでした。(python3と打ち込まないとpython3系が立ち上がらないので)
エイリアスちゃんと設定しないとダメですね。

IDLE立ち上げ(python3系)

なので、試しに「idle3」と打ってみると
「** IDLE can't import Tkinter. Your Python may not be configured for Tk. **」。
掲題のエラーが発生しました。

なんかよくわかりませんが、python3系のpython-tkとやらがちゃんとインストールされてないみたいです。

brew install python-tk

なので、ネットで先人の知恵を拝借しbrewでインストールできるとのことでbrew install python-tkしてみます。

 ~ % brew install python-tk
==> Downloading https://ghcr.io/v2/homebrew/core/python-tk/3.9/manifests/3.9.7
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/python-tk/3.9/blobs/sha256:b7813c594bd1716b3ee8cc6684d2cd12959dc57dd0cd33db4dd477a207bf33ae
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:b7813c594bd1716b3ee8cc6684d2cd12959dc57dd0cd33db4dd477a207
######################################################################## 100.0%
==> Pouring python-tk@3.9--3.9.7.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/python-tk@3.9/3.9.7: 5 files, 132.7KB

インストールできました。

idle3成功

なので、idle3してみます。

 ~ % idle3
f:id:te-tou:20211028001138p:plain
idle3

できました。ちゃんとpython3のIDLEが立ち上がりました。




近頃、pythonいじる前にトラブルばっかりです。↓
www.te-tou.tokyo
www.te-tou.tokyo


www.youtube.com
www.facebook.com