Python 3 Segfault Bug Affecting OS X Mavericks (10.9)
|
So as I'm sure many of you have/will, I updated to OS X Mavericks earlier today. In general, Mavericks feels super snappy and refined. However, soon after installing, I noticed that when running Python 3 interactivly Python segfaults for no apparent reason; clearly a major issue. The good news is this issue only seems to affect Python 3, and only when Python 3 is in interactive mode. This means you can run Python 2 just fine and non-interactive Python 3 features, like doctests, still work. Python 3 graphical applications also seem to work. I'll update this post when I find a solution (or, if you find one, comment below!).
UPDATE:
This problem exists because of this bug: http://bugs.python.org/issue18458. Basically, Python has code in Modules/readline.c that contains a workaround for a bug in libedit however the bug in libedit was fixed and Mavericks comes with the new version of libedit and the workaround now causes Python to segfault. The quick and dirty fix is to disable deadline processing by running the following command (from the bug document):
cd /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload
sudo mv readline.so readline.so.disabled
However this fix comes at the cost of disabling many of Python's history and editing features.
Note: To undo the previous fix run:
cd /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload
sudo mv readline.so.disabled readline.so
It turns out that this bug has already been fixed however the fix is not included in Python's binary installers for OS X. Most likely, since OS X 10.9 is now public, the Python community will soon provide new versions of the binary installers for OS X. However, until that happens, the solution is to uninstall Python and then reinstall via a package manager like Brew. Package managers install software by compiling directly from source so you know that you will always get the latest version. Below are directions.
CAVEAT: Don't follow these directions if you have MacPorts installed. It's never a good to have multiple package managers installed at the same time.
- Uninstall Python. Follow the directions here but substitute in your version number (e.g. replace 2.7 with 3.3).
- Install Xcode form the Mac App Store. Open it, and let it do its initialization.
- Install Xcode command line tools.
xcode-select --install
- Install Homebrew.
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
- Make sure Homebrew is good to go.
brew doctor
Fix any warning that
brew doctor
gives. Usually, they come with a useful explanation. When in doubt, Google it. Once all warnings are fixedbrew doctor
should say "Your system is ready to brew." - Install Python.
brew install python3
And that's it! You should be good to go!
At least for me, my homebrew installation of python 3 works perfectly in interactive mode.
Your writing this While i'm Here, trying to figure out how to turn off my Calculator.
Thanks. Interactive working now.
I am sure this piece of writing has touched all the internet people,
its really really pleasant paragraph on building up new blog.
Can someone help me correcting the python Bug with Mavericks ?
I have important projects to do with python and this is currently impossible
Thanks
Did you try the above steps? Can you give details on what your issue is?
In the linked bug/issue page on python.org the list of affected components lists Python 2.7 as well. How certain is your assessment that Python 2.7 works under OSX Mavericks?
The default OS X installation works fine on my computer. If you installed Python 2.7 from a binary, the fix I gave for Python 3.3 should work just as well for Python 2.7. If you do have issues, when you go to delete files just make sure you delete Python 2.7 rather than 3.3 then rune
brew install python
instead ofbrew install python3
.I love looking through your put up. It is the two helpful and intriguing to me. I will arrive back again to see your new posts.
Excellent prepared. I actually appreciated studying this post, thanks for sharing. I hope that you preserve updating the site.
la ds 3d http://la-ds-3d.asktorihartman.com
The homebrew build for me still breaks
Already downloaded: /Library/Caches/Homebrew/python3-3.3.2.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python3/3.3.2 --enable-ipv6 --dataroo
==> make
"_libintl_textdomain", referenced from:
_PyIntl_textdomain in libpython3.3m.a(_localemodule.o)
It is apparently related to something about the OSX gettext package and Pythons work around. I tried
>brew install gettext
which works, but then it tells me it is keg-only. am I even going in the right direction ?
So you mean Python installed but the interactive interpreter still crashes? Keg-only means that the formula installed into Homebrew's directory (/usr/local/Cellar) properly however it wasn't linked in the normal places (e.g. /usr/local/bin/ etc.) because there is already another version of the same software there. Since the links in these key folders (the ones that appear in your PATH) still point to the old version, when you run a program that goes and looks for gettext it still finds the old version. A quick and dirty test to see if this is the case would be to run
export PATH=/usr/local/Cellar/:$PATH
. If Python works properly after making this change you know that what I suggested is correct. For a permanent fix, you're going to need to remove references to the old version of gettext and add symbolic links to the new version in these folders. Let me know if you need help doing this.Still segfaults
>export PATH=/usr/local/Cellar/:$PATH
> python3
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
>>> 1
Segmentation fault: 11
and the stack trace
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 readline.so 0x00000001007d2f67 call_readline + 647
1 org.python.python 0x0000000100008d92 PyOS_Readline + 274
2 org.python.python 0x000000010000ac58 tok_nextc + 104
3 org.python.python 0x000000010000b301 tok_get + 97
4 org.python.python 0x000000010000c771 PyTokenizer_Get + 17
5 org.python.python 0x0000000100008ea4 parsetok + 212
6 org.python.python 0x00000001001060e3 PyParser_ASTFromFile + 131
7 org.python.python 0x00000001001062eb PyRun_InteractiveOneFlags + 283
8 org.python.python 0x000000010010663e PyRun_InteractiveLoopFlags + 78
9 org.python.python 0x0000000100107f51 PyRun_AnyFileExFlags + 161
10 org.python.python 0x000000010011e94e Py_Main + 3454
What does
ls /usr/local/Cellar/
output?Also, when you installed Python from Brew did you make sure that you uninstalled the Python that you currently had installed (step 1 in my directions)?
In Cellar I have
gdbm pkg-config sqlite
gettext readline xz
and in bin I have many programs.
I have /usr/local/Cellar: at the start of my path, so I should be getting the Cellar version of gettext and readline
which python is /usr/local/bin/python
As far as I can tell, there is a workaround in Python for a former bug in gettext on old OSX that the new OSX doesn't have, so I guess I need an old broken gettext build, or a patched Python for Maverick.
Did you ever try deleting Python then reinstalling it from Homebrew? It sounds like you're still running the version of Python that contains the workaround that causes a crash. Make sure you carefully follow each step in this post (Including deleting the old versions of Python).
Very good blog you have here but I was curious about if you knew of any forums that cover the same
topics talked about here? I'd really love to be a part of group where I can get opinions from
other experienced individuals that share the same interest.
If you have any recommendations, please let me know.
Cheers!
Do you know about Hacker News? (news.ycombinator.com) Basically its a social network for tech news that always has a lot of really interesting articles to read.
Hi Paul
They say you should never uninstall 2.7 but your recommending it ?
Nick
No, I'm recommending uninstalling Python3.