2013-07-24 18 views
3

我的Python的历史文件存在在〜/ .pyhistory并包含以下内容:为什么readline.read_history_file给我“IO错误:[错误2]没有这样的文件或目录”

from project.stuff import * 
quit() 
from project.stuff import * 
my_thing = Thing.objects.get(id=21025) 
my_thing 
my_thing.child_set.all() 
my_thing.current_state 
my_thing.summary_set 
my_thing.summary_set.all() 
[ x.type for x in my_thing.child_set.all() ] 
[ x.type for x in my_thing.child_set.all().order_by('datesubmitted') ] 
quit() 

我使用的virtualenv和virtualenvwrapper构建虚拟环境。今天,我遇到了我的历史文件的readline不读了一个问题:由我

>>> historyPath 
'/Users/johndoe/.pyhistory' 
>>> readline.read_history_file(historyPath) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
IOError: [Errno 2] No such file or directory 

该文件是可读可写的:

[[email protected]]# ls -l ~/.pyhistory 
-rw------- 1 johndoe somegroup 325 21 Sep 2012 /Users/johndoe/.pyhistory 

什么会导致这个问题?

回答

18

您的历史记录文件似乎是旧版本。尝试将其转换为以更高版本的readline的期望的格式,最引人注目的是第一行应该是字面意思_HiStOrY_V2_“和所有空格应替换为“\ 040”:

_HiStOrY_V2_ 
from\040project.stuff\040import\040* 
quit() 
from\040project.stuff\040import\040* 
my_thing\040=\040Thing.objects.get(id=21025) 
my_thing 
my_thing.child_set.all() 
my_thing.current_state 
my_thing.summary_set 
my_thing.summary_set.all() 
[\040x.type\040for\040x\040in\040my_thing.child_set.all()\040] 
[\040x.type\040for\040x\040in\040my_thing.child_set.all().order_by(\040'datesubmitted'\040)\040] 
quit() 

我不知道这是否是底层readline/libedit库或Python readline模块的一个怪癖,但是这对我来说很有用。

+0

将osx升级到小牛后遇到此问题。 readline版本必须已经更新或者其他东西。谢谢。 –

+2

我刚碰到这个。这是非常烦人的,错误是“没有这样的文件或目录”,并且它是一个IOError。它应该像readline.FileParseError。并且该消息应该是“历史文件中的预期版本2头文件” – onlynone

+2

我刚发现这是GNU的readline vs BSD的libedit的问题。我有一个virtualenv,其readline是针对libedit编译的。它是libedit,期望有趣的标题和\ 040而不是空格。我系统范围的自制python使用的readline是针对GNU的readline编译的,它编写的历史文件没有标题和常规空格。我通过删除virtualenv并重新创建它来解决问题,以便它将指向与系统python相同的readline.so。 – onlynone

相关问题