如何在Eclipse中使用PyDev添加断点?

3
我想在一个PyDev项目中添加断点。我正在使用带有PyDev插件的Eclipse。我在运行Windows 7。我想要调试的文件位于C:\cygwin\workspace\project\main.py。
当我尝试通过双击我想要断点的那一行左侧来添加断点时,该断点似乎已经在文件中出现了,但是当我单击“调试”时,我会收到以下错误:
pydev debugger: warning: trying to add breakpoint to file that does not exist: /workspace/project/C:\cygwin\workspace\project\main.py

请注意,该文件在调试模式和正常运行模式下仍然可以正常运行。我也可以通过在终端中运行python main.py命令来运行该文件。
3个回答

4

我实际上已经成功地解决了这个问题。我意识到我在使用PyCharm,但是由于它们都使用PyDev,所以解决方案应该很容易适应。基本问题是IDE期望Windows路径,而PyDev期望Cygwin路径。我找到了在PyDev中进行这些转换的适当位置。

这是我的设置

  • 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('/','\\')
    

根据需要调整路径。帮助我理解这一点的关键是在PyCharm运行/调试配置的环境变量中添加PYCHARM_DEBUG=True

希望这能帮助其他人节省掉我花了6个小时才弄明白的时间!


1

Cygwin在PyDev中并没有得到很好的支持,因此你要么必须在Windows上使用Python的Windows发行版,要么必须在Linux上使用Python的Linux版本。

真正的问题是,在Cygwin中每一步都必须来回转换路径(与IDE进行通信)......在这方面已经做了一些初步工作,但没有进展......

一个我没有真正尝试过但可能有效的方法是尝试在Cygwin中使用所有内容(即:在Cygwin内部运行PyDev:Java/Eclipse/PyDev的Linux版本--不仅仅是Python解释器,这样两者将以相同的方式查看路径),但我没有真正测试过这个设置,所以我不能百分之百确定它会起作用。


0

pydev调试器:警告:尝试添加断点到不存在的文件:/vagrant/pytest/C:\Program Files\Git\vagrant\vagrant\pytest\remote.py(将不起作用)

上述错误一直在发生。我正在使用安装了pydev的eclipse。

最初,我错误地配置了PATHS_FROM_ECLIPSE_TO_PYTHON值,但后来进行了更新。但是更新后的值没有反映在上述错误中,仍然显示旧值。

如何清除旧的配置PATHS_FROM_ECLIPSE_TO_PYTHON并在执行文件时使用最新值?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接