Mac: 2008年3月アーカイブ

  • OS10.5
  • macportsでpython2.5.2を入れてる。標準のpythonは使わない。

Tkinterを使いたい。

tkinterを使おうと思ったらエラーがでた。

>>> import Tkinter
Traceback (most recent call last):
  File "", line 1, in 
  File "/opt/local/lib/python2.5/lib-tk/Tkinter.py", line 38, in 
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter

じゃ、入れればいいんだよね。という訳で、macportsを使ってインストール。

$ sudo port install py25-tkinter
Password:
--->  Fetching tcl
--->  Attempting to fetch tcl8.5.1-src.tar.gz from http://downloads.sourceforge.net/tcl
--->  Verifying checksum(s) for tcl
--->  Extracting tcl
--->  Configuring tcl
--->  Building tcl with target all
--->  Staging tcl into destroot
--->  Installing tcl 8.5.1_0
--->  Activating tcl 8.5.1_0
--->  Cleaning tcl
--->  Fetching tk
--->  Attempting to fetch tk8.5.1-src.tar.gz from http://downloads.sourceforge.net/tcl
--->  Verifying checksum(s) for tk
--->  Extracting tk
--->  Configuring tk
--->  Building tk with target all
--->  Staging tk into destroot
--->  Installing tk 8.5.1_0
--->  Activating tk 8.5.1_0
--->  Cleaning tk
--->  Fetching py25-tkinter
--->  Verifying checksum(s) for py25-tkinter
--->  Extracting py25-tkinter
--->  Configuring py25-tkinter
--->  Building py25-tkinter with target build
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-tkinter/work/Python-2.5.2/Modules" && /opt/local/bin/python2.5 setup.py build " returned error 1
Command output: running build
running build_ext
building '_tkinter' extension
creating build
creating build/temp.macosx-10.3-i386-2.5
-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/opt/local/include -I/opt/local/include/python2.5 -c _tkinter.c -o build/temp.macosx-10.3-i386-2.5/_tkinter.o
unable to execute -DNDEBUG: No such file or directory
error: command '-DNDEBUG' failed with exit status 1

Error: Status 1 encountered during processing.

エラーが出ちゃった。もう一回トライ。

$ sudo port install py25-tkinter
Password:
--->  Building py25-tkinter with target build
--->  Staging py25-tkinter into destroot
--->  Installing py25-tkinter 2.5.2_0
--->  Activating py25-tkinter 2.5.2_0
--->  Cleaning py25-tkinter

うまくいった。

$ python
Python 2.5.2 (r252:60911, Mar 10 2008, 01:23:52) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>

うまくTkinterがimportできた。

参考

MacPortsでステキなUNIXツールをインストール
Tkinter と py2exe
なんかいろいろ蹴躓くなぁ - py25-tkinter 編
2. Widget を配置しよう