有关在调试模式下编译Python的问题 [英] Questions about compiling Python in debug mode
问题描述
我正在使用Ubuntu 12.04,Python 2.7.3。
我在共同编写的 C
扩展程序中遇到分段错误。它似乎来自没有正确释放的指针。
I am using Ubuntu 12.04, Python 2.7.3.
I am having a segmentation fault in a C
extension I have co-written. It seems to come from a pointer that was not free'd properly.
然后我使用 valgrind
查找内存泄漏。根据 answer ,我必须编译 Python
在调试模式下获得 valgrind
友好版本的 Python
并摆脱它的无关紧要报告。
I then use valgrind
to find memory leaks. According to that answer, I have to compile Python
in debug mode to get a valgrind
friendly version of Python
and get rid of its irrelevant reports.
如何在调试模式下编译 Python
?
How to compile Python
in debug mode?
即使我链接的答案回答了该问题的一部分,也无法为我提供足够的详细信息。
实际上,我想了解什么是发生,不仅是因为在某些地方键入内容,是因为谁知道?它可能起作用。
Even though the answer I linked answers part of that question, it does not provide me enough details.
Indeed, I want to understand what is happening, not just type things at some places because "who knows? It could work".
因此,我想知道:
- 要下载的内容进行编译Python?
- 在哪里键入
./ configure
? - 将要发生什么我当前的安装?
我已经在许多地方读到Ubuntu 12.04上的许多进程都是由Python管理的
,我不想弄乱任何东西。
我还试图找到Yair Daon评论中提到的问题的答案:
I am also trying to find answers to the questions mentioned by Yair Daon's comment:
-
使用调试
编译完成后,是否必须重新编译Python
?
- 如果是,如何将
Python
编译回其标准模式?
- If yes, how to compile
Python
back to its standard mode?
推荐答案
以下是任何尝试在Ubuntu上以调试模式编译Python的人的输入:
Here are some inputs for anyone trying to compile Python in debug mode on Ubuntu:
- 从 Python网站。
-
使用
tar -xf
将其解压缩,然后转到新目录。
- Download the version you need from the python website.
Untar it using
tar -xf
and go to the new directory.
示例:
tar -xf Python2.7.3.tgz
cd Python-2.7.3
使用为调试模式配置python安装程序。/configure--with-pydebug
。它将创建一个只需运行的 Makefile
。
Configure your python installer for debug mode, using ./configure --with-pydebug
. It will create a Makefile
that you will just have to run.
使用以下命令运行 Makefile
来编译源代码,以创建新的python解释器。 $ c>进行安装。
Compile the sources to create your new python interpreter by running the Makefile
, using: make install
.
创建新的解释器时,系统的Python将保持干净。
As you create a new interpreter, your system's Python will stay clean.
如果使用-prefix = / home / username / workspace / project / python /
进行编译,则您现在可以使用以下新Python解释器运行脚本:
If you compiled it using --prefix=/home/username/workspace/project/python/
, you can now run your script with your new Python interpreter using:
/ home / username / workspace / project / python / bin / python script.py
或者,您也可以添加shebang行#!/ home / username / workspace / project / python / bin / python
在脚本的开头,为其赋予执行特权( sudo chmod 764 script.py
),并使用您的脚本更轻松地运行它键入 ./ script.py
来新建Python解释器。
Or, you can also add the shebang line #!/home/username/workspace/project/python/bin/python
at the beginning of your script, give it the execute privilege (sudo chmod 764 script.py
) and run it more easily using your new Python interpreter by typing ./script.py
.
注意:您可能需要查看Python的文档以了解更多信息配置/编译标志
(例如-前缀/ -j ,感谢克里斯的链接。)
Note: you may want to check Python's documentation for more configuring / compiling flags (such as --prefix / -j, thanks Chris for the link).
这篇关于有关在调试模式下编译Python的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!