Python NameError: name 'readline' is not defined

Python 2.6.×已经装了有一定时日了,已经完全不知道python的世界都更新到什么境界了;标题这个issue在我更新到Lion之前就已经存在了,所以这不能算是Lion里才introduce的issue,这个还是得有一句说一句; 之前我在Snow Leopard一直没有找到fix的办法,当然主要的原因还在于我也没有那么急切的想fix它,至少对于一个几个月都基本不碰python的家伙而言,它的急迫性显然没有解决starcraft2破解版一联机就自动更新不能玩这个issue来的高,xd:) BTW, 我只玩战役模式,Blizzard及其各路partner已经完全将starcraft2的对战模式变成网游,虽然我很想支持暴雪买正版,但是网游的各种消耗对我来说是无法容忍的. 貌似又有跑题的趋势…… anyway…… 这个issue就是下面这样的,注意倒数第二行: [cc lang=”bash”] ~ ➔ python Python 2.6.6 (r266:84292, Sep 13 2010, 20:53:06) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. Module readline not available. Traceback (most recent call last): File “/Users/samson/.pythonrc”, line 22, in readline.read_history_file(historyPath) NameError: name ‘readline’ is not defined >>> [/cc] 主要的原因在于我起来的python cli会去读我home目录下.pythonrc ((这个在环境变量$PYTHONSTARTUP里面设置)),.pythonrc的前面几行则会试图去load readline或rlcompleter: [cc lang=”python”] try: import readline except ImportError: print(“Module readline not available.”) else: import rlcompleter readline.parse_and_bind(“tab: complete”) [/cc] 而诡异的是我明明装了readline,还装了两个(当然active的只有一个),这个python却始终很傻的说找不到: [cc lang=”bash”] ~ ➔ port installed | grep readline readline @6.1.000_1+darwin readline @6.1.002_0 (active) [/cc] 我曾试图upgrade python,但是问题仍旧存在,当然真相永远只有一个…… 不废话也不卖关子,最后的解决办法非常吐血,不是upgrade python也不是去装py-readline,而是再install一遍readline (当然最后turns out readline也升级了): [cc lang=”bash”] ~ ➔ sudo port install readline [/cc] [cc lang=”bash”] ~ ➔ port installed | grep readline readline @6.1.000_1+darwin readline @6.1.002_0 readline @6.2.000_0 (active) [/cc] problem solved: [cc lang=”bash”] ~ ➔ python Python 2.6.6 (r266:84292, Sep 13 2010, 20:53:06) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. >>> [/cc]

Buy me a coffee
  • Post author: Samson Wu
  • Post link: 3386.html
  • Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.
0%