Python 分段错误:OS X 中的 11

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19531969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:59:37  来源:igfitidea点击:

Segmentation fault: 11 in OS X

pythonmacos

提问by IncongruentModulo1

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:

我在 OSX 10.9 上的 Python 3.3.2 中遇到了一个问题,如果我在终端窗口中打开 Python,它会在我输入的第二行之后以“Segmentation error: 11”退出,而不管这两个命令是什么。例如,如果我输入:

>>> 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.

然后当我在第二行按回车键时出现错误。我还可以运行超过 2 行的脚本而不会出现任何问题。

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

我今天下午更新到 OSX 10.9,所以我怀疑可能是这样。

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.

但是,我最近刚刚安装了 IPython(以及其他几个软件包)并且过去几天一直在使用它,所以它可能是我最近安装的其他东西。我在运行 configure.py 的地方安装 PyQt 时有几次不成功的尝试,但随后“make”命令失败了,我也对此表示怀疑。

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.

我尝试重新安装 Python,但没有解决问题。IPython 和 IDLE 都可以正常工作。我只是担心潜在的问题是什么。

采纳答案by Robert T. McGibbon

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.

这是 python 中 readline 兼容性的一个错误,与 OSX10.9 中引入的更改有关。本周末,发布了 Python2.7.6 和 Python3.3.3 的候选版本,修复了这个错误。下载链接如下。

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

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

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

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

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

这是问题,引自 Ned Deily,写在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.

周二,Apple 发布了 OS X 10.9(又名 Mavericks)。人们已经对它产生了很大的兴趣,部分原因是苹果免费提供了它,并且让拥有 10.8、10.7 和(大多数)10.6 系统的用户可以轻松地直接升级到 10.9。不幸的是,我们在 OS X 10.9 上的当前维护版本(3.3.2 和 2.7.5)存在问题,需要尽快发布新的维护版本。

一个很重要,因为它会导致解释器在交互模式下运行时崩溃 ( http://bugs.python.org/issue18458)。这个问题是由于 libedit 的 readline 兼容层中长期存在的兼容性问题,上游终于修复了这个问题,Apple 现在已经在 10.9 中发货了。由于 python.org 安装程序动态链接到 libedit,因此当用户以交互方式键入第二个命令时,readline.c 中针对历史索引中原始设计缺陷的原始解决方法现在会导致 10.9 上的段错误。不好。Ronald 设计了一个修复程序,允许 readline.so 在运行时检测和使用任一版本的 libedit,以便我们继续在多个 OS X 版本之间保持二进制兼容性。该修复程序已经在 3.4.0 alphas 中发布,并反向移植到 3.3 和 2.7 分支,等待在那里发布。就在过去的 12 小时内,用户报告的问题至少有四次重复。我已经更新了原始问题以明确提及 10.9,现在它不再属于保密协议,并为没有经验的用户提供可下载的脚本,以通过“删除”readline.so 来解决该问题。据推测,随着消息的传出,打开的重复问题将会减少,但影响仍然存在。

回答by Ashwin Balamohan

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

升级到 OS X 10.9 并使用 Python 网站上提供的补丁后我遇到了这个问题:http: //bugs.python.org/issue18458#msg201087

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

要使用它,请在 Terminal.app(或其他 shell)中打开一个终端会话,然后输入:

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

然后
sh ./patch_readline_issue_18458.sh

Enter your password, if prompted

如果有提示,请输入密码

回答by Brian Lamb

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

我遇到了类似的“分段错误 11”错误,但对我来说它使用的是 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

这是试图使用通过 .mpkg 安装程序安装的 Python 2.7.8 和 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

我认为更新到 2.7.8 会解决这个问题,但似乎 mercurial 仍在寻找 System/Library/Frameworks/Python.framework/Versions/2.7

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

即使在尝试遵循这个有点不明智的建议之后,事情仍然没有奏效。我会跑

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

would get 'segmentation fault 11'

会得到“分段错误 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 homebrewusing that to get the 2.7.8 release (as of Dec 2014)

最后,我的解决方案似乎来自(重新)使用自制软件安装 python以获得 2.7.8 版本(截至 2014 年 12 月)

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.

然后我用 brew install mercurial 重新安装了 mercurial,这似乎解决了导致这种情况的任何依赖项。我希望我能更好地理解 Seg 故障发生了什么,但无法深入了解。

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

我仍然有最好的猜测是,尽管 2.7.8 安装正确并且 usr/local/bin 是路径中的第一个,但 mercurial 仍在引用系统 python

/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

/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: 没有那个文件或目录

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

因此,我的建议是使用 brew 更新 python 安装,然后重新安装您依赖的任何其他软件包。

回答by kilojoules

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

我有这个问题。将chunksize我的 csv 解析器中的更改为 100 消除了错误。