強火で進め

このブログではプログラム関連の記事を中心に書いてます。

「If this fails your Python may not be configured for Tk」というエラーが発生

Pythonで久しぶりにTkinterを使ったところ import Tkinter の所で以下のエラーが発生しました。

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    import Tkinter
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk

MacPortsでのインストール状況をチェックする為に以下のコマンドを実行。

port installed | grep python
  python24 @2.4.6_7 (active)
  python25 @2.5.5_0+darwin+darwin_10+macosx
  python25 @2.5.5_1 (active)
  python26 @2.6.4_0+darwin
  python26 @2.6.6_0+no_tkinter (active)
  xorg-libxcb @1.7_0+python26 (active)
  xorg-xcb-proto @1.6_0+python26 (active)

python26 @2.6.6_0+no_tkinter の所がいかにも怪しいですね。なんで +no_tkinter なんてついてるんでしょ?そりゃ、エラーとなりますね。

色々と試した所、MacPortでPygameをインストールすると +no_tkinter 付きのPythonがActiveになるみたいでした。