2014-04-10 87 views
4
MacBook-Air:~ sgarza62$ 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 % 10 
1 
>>> 10 % 1 
Segmentation fault: 11 

模运算也会发生,如1 % 12 % 2为什么在Python解释器中使用modulo时会出现分段错误?

在这台机器上运行Mac OS 10.9.2。

+0

这似乎是操作系统(或构建)具体。仅供参考:它在linux2上的python2.7 [GCC 4.8.1]上正常工作。 – Hyperboreus

+3

发现它:http://stackoverflow.com/questions/19531969/segmentation-fault-11-in-os-x – Hyperboreus

+0

@Hyperboreus啊,你是对的。我没有意识到,第二个命令总是出现seg断层。感谢您的支持! – sgarza62

回答

1

这与模操作无关。交互式解释程序将在每调用一个命令时崩溃。

操作系统10.9(小牛)升级导致了一些Python版本的不稳定。要解决这个特定的问题,下载并通过终端运行补丁:

>>> curl -O http://bugs.python.org/file32324/patch_readline_issue_18458.sh 
>>> openssl sha1 patch_readline_issue_18458.sh 
>>> sh ./patch_readline_issue_18458.sh 

较新的Python版本已经固定小牛带来的问题。最好安装最新版本https://www.python.org/downloads/

感谢Hyperboreus在问题评论中找到解决方案。

相关问题