65

I am getting an issue in Python 3.3.2 on OSX 10.9 where if I open Python in a terminal window, it exits with "Segmentation error: 11" after the second line I enter, regardless of what the two commands are. For example, if I enter:

>>> for x in range(1000): print(x)

that works fine, but if I enter:

>>> for x in range(1000):
...     print(x)

then I get the error when I press enter on the second line. I can also run a script with more than 2 lines without any problems.

I updated to OSX 10.9 this afternoon, so I suspect that may be it.

However, I just recently installed IPython (along with several other packages) and have been using that the past couple of days, so it could be something else I installed recently. I had a couple unsuccessful attempts at installing PyQt where I ran configure.py but then the "make" command failed, which I was also suspicious of.

I tried reinstalling Python, but it didn't resolve the issue. Both IPython and IDLE work with no problems. I'm just concerned about what could be the underlying issue.

nbro
  • 15,395
  • 32
  • 113
  • 196
IncongruentModulo1
  • 834
  • 1
  • 6
  • 7
  • Can you run gdb on the python instance? – Dhaivat Pandya Oct 23 '13 at 02:58
  • 3
    seems other people are having the same problem: http://stackoverflow.com/questions/18158381/python-crashing-when-running-two-commands the question was closed though, but the 4th comment down might solve your problem – samrap Oct 23 '13 at 03:00
  • Thanks, that's helpful! There seems to be an existing report here: http://bugs.python.org/issue18458 that is listed as fixed. It has a patch listed, but I'm not sure how to use it. – IncongruentModulo1 Oct 23 '13 at 04:00
  • 1
    Either you wait for the next release or you build it yourself from their scm – voondo Oct 23 '13 at 08:42
  • OK, thanks! Since IPython and IDLE both work fine, I think I'll probably just wait. Glad to figure out what the issue is though. – IncongruentModulo1 Oct 23 '13 at 16:18
  • I'm having the same problem except I reinstalled 2.7.5. I tried the solution from the 4th comment on stackoverflow.com/questions/18158381/… mentioned by samrap but that didn't work. Any help would be much appreciated. – SamYoungNY Oct 23 '13 at 20:38
  • 1
    This question appears to be off-topic because it is about something environment related –  Oct 23 '13 at 20:47
  • Here are the instructions on patching the issue: http://bugs.python.org/msg201087 – IncongruentModulo1 Oct 25 '13 at 19:20
  • 1
    Python 2.7.6 RC1 does not resolve this issue for me. Did it work for anyone else? – rjurney Nov 01 '13 at 12:51
  • rjurney, you are seeing a different problem. – Ned Deily Nov 01 '13 at 17:16

4 Answers4

50

This is a bug in the readline compatibility in python, related to changes introduced in OSX10.9. This weekend, release candidates for Python2.7.6 and Python3.3.3 were released which fix this bug. The download links are below.

http://python.org/download/releases/2.7.6/

http://python.org/download/releases/3.3.3/

Here's the issue, quoting from Ned Deily, writing on the python-dev email list.

On Tuesday, Apple released OS X 10.9 (a.k.a. Mavericks). There has already been a lot of interest in it, in part because Apple has made it available for free and has made it easy for users with 10.8, 10.7, and (most) 10.6 systems to upgrade directly to 10.9. Unfortunately, there are issues with our current maintenance releases (3.3.2 and 2.7.5) on OS X 10.9 that call for new maintenance releases as soon as possible.

One is critical in that it causes the interpreter to crash when running in interactive mode (http://bugs.python.org/issue18458). The problem was due to a long-standing compatibility issue in libedit's readline compatibility layer that upstream has finally fixed and Apple has now shipped in 10.9. Because the python.org installers dynamically link to libedit, the original workaround in readline.c for the original design flaw in history indexing now causes a segfault on 10.9 when the user types in the second command interactively. Not good. Ronald devised a fix that allows readline.so at runtime to detect and work with either version of libedit so that we continue to have binary compatibility across multiple OS X releases. That fix is already out in the 3.4.0 alphas and backported to the 3.3 and 2.7 branches, awaiting release there. Just in the last 12 hours, there have been at least four duplicates of the issue reported by users. I've updated the original issue to explicitly mention 10.9, now that it is no longer under NDA, and to provide a downloadable script for inexperienced users to workaround the problem by "removing" readline.so. Presumably, as word gets out, there will be fewer duplicate issues opened but the impact will remain.

Robert T. McGibbon
  • 5,075
  • 3
  • 37
  • 45
  • 1
    I installed 2.7.6 , the error still persists. Am I suppose to do something else? i.e. change the PYTHONPATH ? – venuktan Oct 28 '13 at 22:39
  • You should make sure that everything is referencing the new installation. If your PYTHONPATH or DYLD_LIBRARY_PATH is referencing the old installation, you'll get the error I presume. – Robert T. McGibbon Oct 29 '13 at 00:38
  • yes I finished that part now and its using Python 2.7.6rc1. It crashes when I try to pandas.read_csv and print it. Does not crash anywhere else. – venuktan Oct 29 '13 at 17:58
  • I also install python 2.7.6 RC1 and I also still get the error. Mine is from a pandas DataFrame. See http://stackoverflow.com/questions/19722580/segfault-11-with-pandas-with-python-v2-7-6-rc1-on-mac-os-x-10-9 – rjurney Nov 01 '13 at 10:11
  • 1
    It is extremely unlikely that these pandas-related crashes are in any way related to the readline crash which *is* resolved in 2.7.6rc1. – Ned Deily Nov 01 '13 at 17:17
  • FTR, the pandas crash appears to be due to a bug in Numpy, a bug that has been recently fixed: https://github.com/numpy/numpy/issues/3962 – Ned Deily Nov 01 '13 at 20:19
  • FWIW, brew-installing Python3 did still crash, until I told brew to use a custom OpenSSL library: `brew install python3 --with-brewed-openssl`. – Pascal Jan 23 '14 at 20:26
35

I had this problem after upgrading to OS X 10.9 and used the patch provided on the Python website: http://bugs.python.org/issue18458#msg201087

To use it, open a terminal session in Terminal.app (or other shell), then enter:

curl -O http://bugs.python.org/file32324/patch_readline_issue_18458.sh
openssl sha1 patch_readline_issue_18458.sh
# the digest should be 7cb0ff57820a027dd4ca242eb2418930f8f46b4c

then
sh ./patch_readline_issue_18458.sh

Enter your password, if prompted

Ashwin Balamohan
  • 3,303
  • 2
  • 25
  • 47
  • 1
    I am using OS X 10.9, django 1.5.8, python 2.7, meet the same problem and solved with above script solution. Mark. – spikeyang Jul 14 '14 at 13:19
  • 1
    I am using OS 10.10.1 (Yosemite) and this bug appears again. Your solution does not work in this case. I got the message: " -- running on OS X 10.10.1 -- This patcher is only needed on OS X 10.9.x". Do you know how to fix it with Yosemite? Thanks in advance! – hoang tran Jan 09 '15 at 15:34
  • 2
    I am using OS 10.10.5 and this bug is still there. The solution here does not work. I get the following messages `code` -- running on OS X 10.10.5 -- This patcher is only needed on OS X 10.9.x `code` – Taposh DuttaRoy Aug 08 '16 at 15:41
  • 1
    I had this issue with OS 10.14 and python 3.10.9, I'm not sure this gonna work today! – Ibrahim.H Apr 26 '23 at 10:35
2

I had this problem. Changing the chunksize in my csv parser to 100 eliminated the error.

kilojoules
  • 9,768
  • 18
  • 77
  • 149
1

I was encountering similar 'segmentation fault 11' errors but for me it was using mercurial(hg)

This was trying to use Python 2.7.8 installed via the .mpkg installer and pip install mercurial On OS X 10.9.5

I thought updating to 2.7.8 would have resolved this but it seemed that mercurial was still looking for the System/Library/Frameworks/Python.framework/Versions/2.7

Even after trying to follow this slightly unwise advice Things still weren't working. I would run

hg init
hg add *
hg commit -m ...
hg status

would get 'segmentation fault 11'

The first couple of lines of the stack trace point to this:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   ???                             000000000000000000 0 + 0
1   osutil.so                       0x00000001095ef768 listdir + 313
2   org.python.python               0x0000000109261b35 PyEval_EvalFrameEx + 14712
3   org.python.python               0x000000010925e093 PyEval_EvalCodeEx + 1641

In the end my solution seems to have come from (re)installing python with homebrew using that to get the 2.7.8 release (as of Dec 2014)

I then reinstalled mercurial with brew install mercurial which seems to have resolved whatever dependencies where causing this. I wish I understood better what was happening with the Seg fault but couldn't get to the bottom of it.

The best guess I still have is that mercurial was still referencing the system python despite 2.7.8 being installed properly and usr/local/bin being first in the path

/usr/local/bin:usr/local/git/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:~/Develop:/usr/local/git/bin: No such file or directory

So, what I'm suggesting is updating the python install with brew and then reinstalling whatever other packages you depend on.

Brian Lamb
  • 21
  • 3
  • The version installed by the mpkg from python.org ran as `Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin` and the version that brew installs is `Python 2.7.8 (default, Dec 4 2014, 01:08:07) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin` – Brian Lamb Dec 04 '14 at 06:51