在Windows调试Python解释器还是非常方便的,因为有强大的VS。
不过在Linux下可能有点不那么顺畅。但是稍微设置一下还是可以很方便地调试的。我们来看看在Ubuntu下怎么做。
获取源码
在Ubuntu下获取Python2.7的源码非常方便,只需要使用apt-get就可以轻松取得。在Shell下输入
apt-get source python2.7
即可以将Python的源码下载到当前目录。
然后我们就可以得到一个tar.gz的压缩包。
编译
我们进入源码文件夹后输入
1
2./configure
make
然后就可以编译得到python。
当然,此时的Python不是调试版的,如果要编译调试版的Python,就需要再做一些东西。首先我们可以Google一下怎么做,貌似很多都是引用了源码README的一段话:
command; e.g. “make OPT=-g” will build a debugging version of Python
on most platforms. The default is OPT=-O; a value for OPT in the
environment when the configure script is run overrides this default
(likewise for CC; and the initial value for LIBS is used as the base
set of libraries to link with).
好,我们现在使用
make OPT=-g
试试,嗯,