Fix Python segmentation fault on exit

The “python_history” file contains recent commands entered into the Python interpreter. “python_history” files with incorrect permissions can cause a message on exiting Python like:

Error in atexit._run_exitfuncs:
PermissionError: [Errno 13] Permission denied

Find the owner of ~/.python_history

  • macOS / Linux: ls -l ~/.python_history
  • Windows / PowerShell: (get-acl ~/.python_history).owner

If it does not show the current username, that’s likely the problem.

Fix

This changes the file ownership to the current user.

  • macOS / Linux: chown $whoami:$whoami ~/.python_history
  • Windows PowerShell: takeown /f $home\.python_history

Notes