简体   繁体   English

如何使用pydev在eclipse中添加断点?

[英]How do I add a breakpoint in eclipse using pydev?

I would like to add a breakpoint to a pydev project. 我想在pydev项目中添加一个断点。 I am using eclipse with the pydev plugin. 我在pydev插件中使用eclipse。 I am running Windows 7. The file I want to debug is located at C:\\cygwin\\workspace\\project\\main.py . 我正在运行Windows7。要调试的文件位于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: 当我尝试通过双击要在其上的断点的行的左侧添加断点时,该断点似乎在文件中以视觉方式出现,但是当我单击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 . 我也可以通过运行python main.py在ide之外运行文件。

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. 我意识到我正在使用PyCharm,但是该解决方案应该易于调整,因为他们俩都使用PyDev。 The basic problem is that the IDE is expecting windows paths while PyDev is expecting cygwin paths. 基本问题是IDE期望Windows路径,而PyDev期望cygwin路径。 I found the appropriate places in PyDev to do those conversions. 我在PyDev中找到了进行这些转换的适当位置。

Here's my setup 这是我的设置

  • configure your project to use a python for cygwin binary (this may not be necessary) 配置项目以将python用于cygwin二进制文件(可能没有必要)
  • edit Program Files/JetBrains/PyCharm 2.5/helpers/pydev/pydevd.py. 编辑程序文件/ JetBrains / PyCharm 2.5 / helpers / pydev / pydevd.py。 This converts the paths sent to the debugger to cygwin paths. 这会将发送到调试器的路径转换为cygwin路径。 Around line 597, where file = NormFileToServer(file) is located, make the following changes 在第597行file = NormFileToServer(file)所在的位置file = NormFileToServer(file)周围,​​进行以下更改

      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 稍后在elif cmd_id == CMD_REMOVE_BREAK语句下进行几行相同的文件名转换

  • edit Program Files/JetBrains/PyCharm 2.5/helpers/pydev/pydevd_comm.py. 编辑程序文件/ JetBrains / PyCharm 2.5 / helpers / pydev / pydevd_comm.py。 This converts paths sent back to pycharm into windows paths. 这会将发送回pycharm的路径转换为Windows路径。 Around line 549 alter the code to look like this: 在549行周围,将代码更改为如下所示:

      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. 帮助我弄清楚这一点的最大事情是在PyCharm运行/调试配置的环境变量中添加了PYCHARM_DEBUG=True

Hope this saves someone else the 6 hours I spent figuring this out! 希望这可以节省我花了6个小时才解决的其他人!

Cygwin is not really properly supported in PyDev, thus, you either must work on windows using a python windows distribution or you must work on Linux using a python for linux... Cygwin在PyDev中并未真正得到正确的支持,因此,您必须使用python Windows发行版在Windows上工作,或者您必须使用适用于Linux的python在Linux上工作...

The real issue is that the paths must be translated back and forth at each step when inside cygwin (to make the communication with the IDE)... some initial work has been done on that front, but it didn't go forward... 真正的问题是,在cygwin内部(与IDE进行通信)时,必须在每个步骤之间来回转换路径(在与IDE进行通信时...)在此方面已进行了一些初步的工作,但没有进行。 。

One approach I didn't really attempt but which could work could be trying to use all within cygwin (ie: use PyDev running inside cygwin too: the linux version of java/eclipse/pydev -- not only the python interpreter, that way both would see paths in the same way), but I haven't really tested that setup, so, I'm not 100% certain it'll work. 我没有真正尝试过但可行的一种方法可能是尝试在cygwin中使用所有方法(即:也使用在cygwin中运行的PyDev:java / eclipse / pydev的Linux版本-不仅是python解释器,而且会以相同的方式看到路径),但我尚未真正测试过该设置,因此,我不确定100%会起作用。

pydev debugger: warning: trying to add breakpoint to file that does not exist: /vagrant/pytest/C:\\Program Files\\Git\\vagrant\\vagrant\\pytest\\remote.py (will have no effect) pydev调试器:警告:尝试将断点添加到不存在的文件中:/ vagrant / pytest / C:\\ Program Files \\ Git \\ vagrant \\ vagrant \\ pytest \\ remote.py(将无效)

The above error is keeping on occuring to me. 我一直在发生以上错误。 I am using eclipse with pydev installed. 我正在使用安装了pydev的eclipse。

INitiualy I configured the PATHS_FROM_ECLIPSE_TO_PYTHON value wrongly but then updated it. 最初,我错误地配置了PATHS_FROM_ECLIPSE_TO_PYTHON值,但随后对其进行了更新。 But the updated value is not reflecting in the above error but shows old value only. 但是更新的值不会反映在上述错误中,而只会显示旧值。

How to flush the old configurtion PATHS_FROM_ECLIPSE_TO_PYTHON and make the latest value used when executing the file 如何刷新旧配置PATHS_FROM_ECLIPSE_TO_PYTHON并执行文件时使最新值使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM