编译Python发生Segmentation fault 错误的解决方法

1. 错误重现

/bin/sh: line 1: 41686 Segmentation fault      (core dumped) CC='gcc -pthread' 
LDSHARED='gcc -pthread -shared ' OPT='-DNDEBUG -g -fwrapv -O3 -Wall 
-Wstrict-prototypes' ./python -E ./setup.py build

make: *** [sharedmods] Error 1

2. 解决方法

编译时加上--with-pydebug参数即可,例如编译python2.6:
./configure --prefix=/usr/local/python2.6 --with-pydebug