old school magic

機械学習に関する備忘録です。

OS X Mavericksにpyreadlineがうまく入らない(けどよく考えたら必要なかった)話

python3でiPyhtonをインストールしようとした時に、適当にググって「windowsだとpyreadlineがいるのか、とりあえずmacでも入れよう」と思いインストールし、iPythonを入れたら起動時にエラーが出ました。

Traceback (most recent call last):
  File "/usr/local/bin/ipython3", line 9, in <module>
    load_entry_point('ipython==1.1.0', 'console_scripts', 'ipython3')()
  File "/usr/local/lib/python3.3/site-packages/IPython/__init__.py", line 118, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/IPython/config/application.py", line 544, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "/usr/local/lib/python3.3/site-packages/IPython/config/application.py", line 89, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/IPython/terminal/ipapp.py", line 323, in initialize
    self.init_shell()
  File "/usr/local/lib/python3.3/site-packages/IPython/terminal/ipapp.py", line 339, in init_shell
    ipython_dir=self.ipython_dir, user_ns=self.user_ns)
  File "/usr/local/lib/python3.3/site-packages/IPython/config/configurable.py", line 349, in instance
    inst = cls(*args, **kwargs)
  File "/usr/local/lib/python3.3/site-packages/IPython/terminal/interactiveshell.py", line 320, in __init__
    **kwargs
  File "/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py", line 475, in __init__
    self.init_readline()
  File "/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py", line 1784, in init_readline
    import IPython.utils.rlineimpl as readline
  File "/usr/local/lib/python3.3/site-packages/IPython/utils/rlineimpl.py", line 28, in <module>
    from readline import *
  File "/usr/local/lib/python3.3/site-packages/readline.py", line 6, in <module>
    from pyreadline.rlmain import Readline
  File "/usr/local/lib/python3.3/site-packages/pyreadline/__init__.py", line 11, in <module>
    from . import unicode_helper, logger, clipboard, lineeditor, modes, console
  File "/usr/local/lib/python3.3/site-packages/pyreadline/clipboard/__init__.py", line 13, in <module>
    from .win32_clipboard import GetClipboardText, SetClipboardText
  File "/usr/local/lib/python3.3/site-packages/pyreadline/clipboard/win32_clipboard.py", line 37, in <module>
    from pyreadline.keysyms.winconstants import CF_UNICODETEXT, GHND
  File "/usr/local/lib/python3.3/site-packages/pyreadline/keysyms/__init__.py", line 23, in <module>
    raise ImportError("Could not import keysym for local pythonversion", x)
NameError: name 'x' is not defined

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    c.Application.verbose_crash=True 

pyreadlineのエラーっぽかったので再インストールしてみたら、

$pip3 install pyreadline
Downloading/unpacking pyreadline
  Downloading pyreadline-2.0.zip (108kB): 108kB downloaded
  Running setup.py egg_info for package pyreadline
    
    package init file 'pyreadline/configuration/__init__.py' not found (or not a regular file)
Installing collected packages: pyreadline
  Running setup.py install for pyreadline
    package init file 'pyreadline/configuration/__init__.py' not found (or not a regular file)

Successfully installed pyreadline

って感じのエラーが出てました。

__init__.pyが見つかってないのにインストール成功ってでて、それが原因でiPythonの起動エラーが起きてる...?

対処のしようがなかったので、pyreadlineをアンインストールしてiPython起動してみたらちゃんと起動しました。

結論

mac(OS X Mavericks)でiPython使うのにpyreadlineは必要ない、というか入れたら起動しなくなる

iPythonのmacでの正しいインストール法

iPythonインストールするのにこちらの記事が参考になりました。
IPythonをインストールして使い始めた: 黄昏てなんかいられない
僕は何となくpyreadlineを入れてしまいこけましたが、この記事の通りやればうまく行くと思います。