Why does readline.read_history_file give me 'IOError: [Errno 2] No such file or directory'
python, python-2.7, readline
Solution
Your history file appears to be an older version. Try converting it to the format expected by later versions of readline, most notably the first line should be literally '_HiStOrY_V2_' and all spaces should be replaced with '\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()
I am not sure whether this is a quirk of the underlying readline/libedit library or the Python readline module, but this is what worked for me.
Problem
My Python history file exists at ~/.pyhistory and contains the following: ``` 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() ``` I'm using virtualenv and virtualenvwrapper to build virtual environments. Today I'm having a problem with readline not reading in my history file: ``` >>> 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 ``` The file is readable and writable by me: ``` [johndoe@here]# ls -l ~/.pyhistory -rw------- 1 johndoe somegroup 325 21 Sep 2012 /Users/johndoe/.pyhistory ``` What could cause this problem?