Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile Python extension with debug info using PIP

I have source code for an extension in Python. I want to see debug symbols for that extension when I debug it. How do I tell PIP to compile and link debug symbols for my extension?

(Preferably platform agnostic, else Linux)

like image 657
user Avatar asked May 10 '15 16:05

user


People also ask

How do I debug an extension Python?

In order to debug the C/C++ code of an extension, you need to use the native debugger, GDB or LLDB, and debug the interpreter process that loads your script and runs the application. For that, you can either attach to a running Python process or debug a properly configured Custom Build Application.

How do I run a Python script in debug mode in Terminal?

Directly use command python pdg-debug.py without -m pdb to run the code. The program will automatically break at the position of pdb. set_trace() and enter the pdb debugging environment. You can use the command p variable to view the variables or use the command c to continue to run.

How do I debug Python code in Visual Studio?

Python in Visual Studio supports debugging without a project. With a stand-alone Python file open, right-click in the editor, select Start with Debugging, and Visual Studio launches the script with the global default environment (see Python environments) and no arguments.


1 Answers

You need to invoke setup.py's build command with --debug flag during package installation. Using pip additional flags to setup.py can be passed using --global-option:

pip install --no-binary :all: --global-option build --global-option --debug PACKAGE

In case of errors try upgrading pip and setuptools:

pip install -U setuptools
pip install -U pip

I found this information in this blogpost by Jonathan Lange: https://jml.io/2015/08/debugging-python-with-gdb.html

like image 199
rutsky Avatar answered Oct 21 '22 19:10

rutsky