Cam Cam - 3 months ago 50
Python Question

How do I add a breakpoint in eclipse using pydev?

I would like to add a breakpoint to a pydev project. I am using eclipse with the pydev plugin. I am running Windows 7. The file I want to debug is located at C:\cygwin\workspace\project\main.py .

When I attempt to add the breakpoint by double-clicking to the left of the line on which I want the breakpoint, the breakpoint appears to be visually present in the file, but then I get this error when I click debug:

pydev debugger: warning: trying to add breakpoint to file that does not exist: /workspace/project/C:\cygwin\workspace\project\main.py


Note that the file still appears to run fine both in debug and normal run modes. I can also run the file outside the ide by running
python main.py
.

Answer

I was actually able to get this working. I realize I'm using PyCharm, but the solution should be easily adapted since they both use PyDev. The basic problem is that the IDE is expecting windows paths while PyDev is expecting cygwin paths. I found the appropriate places in PyDev to do those conversions.

Here's my setup

  • configure your project to use a python for cygwin binary (this may not be necessary)
  • edit Program Files/JetBrains/PyCharm 2.5/helpers/pydev/pydevd.py. This converts the paths sent to the debugger to cygwin paths. Around line 597, where file = NormFileToServer(file) is located, make the following changes

                orig_file = file
                file = NormFileToServer(file)
    
                if not os.path.exists(file):
    
                    file = orig_file.replace('c:/cygwin','')
                    file = file.replace('\\','/')
                    file = file.replace(' ','\ ')
                    file = NormFileToServer(file)
    
                    if not os.path.exists(file):
                        sys.stderr.write('pydev debugger: warning: trying to add breakpoint'\
                            ' to file that does not exist: %s (will have no effect)\n' % (file,))
                        sys.stderr.flush()
    

    do the same filename conversion a few lines later under the elif cmd_id == CMD_REMOVE_BREAK statement

  • edit Program Files/JetBrains/PyCharm 2.5/helpers/pydev/pydevd_comm.py. This converts paths sent back to pycharm into windows paths. Around line 549 alter the code to look like this:

                myFile = pydevd_file_utils.NormFileToClient(curFrame.f_code.co_filename)
                myFile = "C:\cygwin" + myFile
                myFile = myFile.replace('/','\\')
    

Adjust the paths as needed. The big thing that helped me figure this out was to add PYCHARM_DEBUG=True in the environment variables of the PyCharm run/debug configurations.

Hope this saves someone else the 6 hours I spent figuring this out!

Comments