Windows でも Python curses を使いたいんですが

powered by Fotopedia

Linuxcurses が使えたので、Windows でもやってみたいというのが人情です

さっそく WinXp で試したところ、CentOS 5.7 と同じく import でこけました 

C:\Documents and Settings\user1>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\Tools\Python27\lib\curses\__init__.py", line 15, in 
    from _curses import *
ImportError: No module named _curses
>>>

はい、残念!

そこで下のサイトに "as is" で提供してくださっている curses のバイナリをインストールしてみます
大変、ありがたいです

Unofficial Windows Binaries for Python Extension Packages
http://www.lfd.uci.edu/~gohlke/pythonlibs/
http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses 
curses-2.2.win32-py2.7.‌exe

早速、やり直して見ると import できたようです

C:\Documents and Settings\user1>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>>

 

では下の記事で書いたサンプルを動かしてみましょう

PythonCurses のサンプルを書いてみた
 http://quwahara.hatenablog.com/entry/2012/02/22/222102

 https://gist.github.com/1885105

どうやらいいようです

f:id:quwahara:20120223000133p:plain

 Python の移植性がすばらしい