Search code examples
pythondebuggingpython-idleegg

How to debug a python source file within a .egg file


I am trying to debug an error in a python script that uses code in a module which is bundled as a .egg file.

Using the IDLE 3.6.3 debugger (NB: the title of the debugger window is "Debug Control"), it is able to trace the commands that were executed in the various modules as well as the local and global variables available at the time those lines of code were executed. This is regardless of whether the source script is in a .egg file or not.

For lines of code from a script that is not in a .egg file (but in a folder on the PC), I am able to access the source file from IDLE by right-clicking on the line of code in the Debug Control window and then choosing "Go to source line" from the context menu. The source file opens in an IDLE Editor window and the associated line number is highlighted. Within this Editor window, I can right-click on any line and set/clear a breakpoint.

The problem arises when I try to "Go to source line" of a script which is located within an egg file. The debugger is also unable to step into the code in these scripts. I have however been able to extract the script from the egg file and can view it in the IDLE Editor window (or any other text editor).

Is there a way to debug scripts in .egg files which I have been unable to figure out or is there a way to link the source script I have extracted to the debugger so that it does not have to depend on the one in the .egg file? (I am using python version 3.6.3)


Solution

  • An egg file is a specialized zip file that packages together Python modules and other data. The modules can be any of .py(o) python source, .pyc compiled Python, and .exe compiled C(++). Python can import modules from within a zip file. AFAIK, IDLE cannot read text files from within an egg.

    According to the answer by 'kmario23' to the SO question referenced above, one can change .egg to .zip and then explore the contents. You could then tell if any of the modules are .py files.

    I suspect that you could extract the modules into a normal directory with the same name (minus .egg) and have python import the extracted modules. IDLE could then read any .py files. You might need to rename the .egg to, say, .eggback, to prevent its use. I am guessing this from my experience with normal zip files, as I have never manipulated an egg file. There is probably some detail that I have omitted.