I asked over on Stack Overflow, but this seems a problem specific to Mac OS X as the error does not happen on other OS (ubuntu for example).

https://stackoverflow.com/q/42637680/447830 repeated below:

So. I own the file named ~/.osc_history, as shown below:

$ w
17:53  up  3:15, 5 users, load averages: 1.30 1.17 1.10
USER     TTY      FROM              LOGIN@  IDLE WHAT
kyma     console  -                14:39    3:14 -
kyma     s001     -                17:20       - w

$ ls -l ~/.osc_history 
-rw-r--r--  1 kyma  staff  13 Mar  6 17:41 /Users/kyma/.osc_history

$ ls -lO ~/.osc_history 
-rw-r--r--  1 kyma  staff  - 13 Mar  6 17:41 /Users/kyma/.osc_history

The header in the file is correct:

$ cat ~/.osc_history 

From the interactive prompt, the following code runs fine:

$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> import readline
>>> histfile = os.path.join(os.path.expanduser("~"), ".osc_history")
>>> histfile
>>> readline.read_history_file(histfile)
>>> ^D

However, when I attempt to run the following, which I've called "yeuch.py"...

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import readline                 # Command line history
import os.path

histfile = os.path.join(os.path.expanduser("~"), ".osc_history")
if not os.path.isfile(histfile):     # If there's no history file...
    empty = open(histfile, "a")      # ... create an ALMOST empty one...
    empty.write("_HiStOrY_V2_\n")    # ... with the special header line
readline.read_history_file(histfile) # Read history from previous sessions
readline.set_history_length(1000)    # Default length was -1 (infinite)

...I see:

$ python yeuch.py
Traceback (most recent call last):
  File "yeuch.py", line 14, in <module>
    readline.read_history_file(histfile) # Read history from previous sessions
IOError: [Errno 1] Operation not permitted

What the heck's going on? (I hope I'm not overlooking some stupid typo multiple times and am not a readline code expert enough to spot the error myself.)

  • Thanks for linking to the other site. This looks like an interesting question. I expect to learn from attempts to answer and/or a correct answer.
    – bmike
    Commented Mar 7, 2017 at 1:06

1 Answer 1


No sure if you've sorted this out. Just ran into it myself. I can get around this my making the python history file visable.

eg: > cp .pyhistory -> pyhistory

  • 1
    How does that work in the question he has no .pyhistory file. What exact code and error did you get
    – mmmmmm
    Commented Jan 10, 2018 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .