Tuesday, October 22, 2013

Python segfault with OS X 10.9 Mavericks

If you're using python from python.org's mac installer and you've just upgraded to Mavericks, you'll find that the interactive console segfaults after the second command you type:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1
1
>>> 2
[1]    1851 segmentation fault  python3

The root cause is this bug: http://bugs.python.org/issue18458

Though it looks like the issue has been resolved in the source, the fix hasn't made it to the downloadable builds as of this writing. The fix is to use either Apple's included version of Python 2.7.5, or to use python from homebrew.

You'll want to uninstall the existing version of python.  Instructions for that are here. In my case I wanted to remove all python.org versions, so the commands were:

sudo rm -rf /Library/Frameworks/Python.framework
cd /usr/local/bin; 
ls -l . | grep '../Library/Frameworks/Python.framework' | awk '{print $9}' | sudo xargs rm

At this point /usr/bin/python should be the only remaining version in your path and will point to the Apple supplied Python 2.7.5. If you're happy with that, you can stop here!

Note that site packages are within /Library/Frameworks/Python.framework, so any that you've got installed will need to be replaced. To get a decent python package manager back, do:

sudo easy_install pip

If you want Python 3, install it with homebrew.

2 comments:

  1. I am seeing this fault with 2.7.3 and Mavericks:
    Joses-MacBook-Pro:~ jtorrebueno$ python
    Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1+1
    2
    >>> 1+1
    Segmentation fault: 11

    ReplyDelete
    Replies
    1. That would be expected - The 2.7 branch isn't fixed until 2.7.6. So you can solve your problem by:
      1. Switching to system python OR
      2. Switching to brew python OR
      3. Installing 2.7.6 from python.org (https://www.python.org/download/releases/2.7.6)

      Delete