Python:如何使用IDLE调试器在mac上设置断点?

时间:2023-01-18 09:17:19

I have access to both a PC and a mac for a python class. I find I am unable to set breakpoints in the IDLE debugger in the mac (works fine on the PC).

我可以访问PC和mac for python类。我发现我无法在mac中的IDLE调试器中设置断点(在PC上正常工作)。

I've tried "ctrl-click" and configuring the touchpad to recognize two taps at once as a secondary click. I don't have a mouse for the mac, just the touchpad.

我尝试过“按住Ctrl键单击”并将触摸板配置为一次识别两次点击作为辅助点击。我没有Mac的鼠标,只有触摸板。

MAC OS 10.4.10 tiger

MAC OS 10.4.10老虎

Python/IDLE version 2.6.1

Python / IDLE版本2.6.1

I have tried STFW unsuccessfully...

我试过STFW失败了......

4 个解决方案

#1


If you put the following two lines:

如果你把以下两行:

import pdb
pdb.set_trace()

Python will import the Python De Bugger and you will be in the interactive interpreter at this point in the code. It will evaluate all your Python expressions normally.

Python将导入Python De Bugger,您将在代码中的此处进入交互式解释器。它会正常评估所有Python表达式。

The most important commands are:

最重要的命令是:

  1. s - step (forward one command)
  2. s - 步骤(转发一个命令)

  3. c - continue (done)
  4. c - 继续(完成)

For a full list, see this: http://infohost.nmt.edu/tcc/help/pubs/python22/pdb-commands.html

有关完整列表,请参阅:http://infohost.nmt.edu/tcc/help/pubs/python22/pdb-commands.html

#2


Have a look at the pdb module. I have just barely learned about it, and played with it a bit. It appears to enable command line debugging by allowing you to set traces within the code. This gives you interactive access to your variables and code while it is running. Not quite the same as running the IDLE debugger with breakpoints, but it may work for you.
See this or this for more details.

Something else to look at ... under Options -> Configure IDLE -> Keys, there may be a way to map keystrokes to the action of setting a breakpoint.

看看pdb模块。我刚刚学会了它,并且玩了一下。它似乎允许您在代码中设置跟踪来启用命令行调试。这使您可以在变量和代码运行时以交互方式访问它们。与使用断点运行IDLE调试器不完全相同,但它可能适合您。有关详细信息,请参阅此或此内容。要查看的其他内容...在选项 - >配置IDLE - >键下,可能有一种方法可以将击键映射到设置断点的操作。

#3


It's a bug in IDLE, specifically any IDLE on Mac OS X linked with the default Aqua Tk, supplied with Mac OS X or from ActiveState. That includes the Apple-supplied Pythons in OS X 10.4 through 10.6 and the python.org installers. The problem is that Aqua Tk has a different mapping for mouse clicks and, even if that were fixed, IDLE expects users to always have a multi-button mouse. See Issue 10404 for more details and a patch. This should not be an issue if the Python is linked with an X11-based Tk, as is the default with MacPorts.

这是IDLE中的一个错误,特别是Mac OS X上与Mac OS X或ActiveState提供的默认Aqua Tk链接的任何IDLE。这包括OS X 10.4到10.6中Apple提供的Pythons和python.org安装程序。问题是Aqua Tk有一个不同的鼠标点击映射,即使修复了它,IDLE也希望用户总是有一个多键鼠标。有关更多详细信息和修补程序,请参见问题10404。如果Python与基于X11的Tk链接,这应该不是问题,这是MacPorts的默认设置。

#4


So, for newbies, a little more detail on Ned Deily's patch. Here is what I did. I'm running python 2.7.1 in idle on osx 10.6.5. I followed Ned's link for Issue 10404, and finally to the patched version of the file EditorWindow.py, which on my installation lives in the directory

所以,对于新手来说,更多关于Ned Deily补丁的细节。这就是我做的。我在osx 10.6.5上空闲运行python 2.7.1。我按照Ned的问题10404的链接,最后到了EditWindow.py文件的修补版本,我的安装文件位于目录中

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/idlelib

Following more links, we find the patched version of the file is here.

下面是更多链接,我们发现文件的修补版本在这里。

This you can download from the "raw" link to the left on that page. Keep a copy of your old version of EditorWindow.py, then move or copy the new EditorWindow.py from your Download directory to the idlelib directory. Restart idle, and ctrl-click gives drop-down menus for setting breakpoints. This is probably all obvious, but it's the first time I did it so I thought I'd share the mini-steps with other novices. There may be a cleaner way to do it too of course.

您可以从该页面左侧的“原始”链接下载。保留旧版EditorWindow.py的副本,然后将新的EditorWindow.py从Download目录移动或复制到idlelib目录。重新启动空闲,然后按住ctrl-click提供设置断点的下拉菜单。这可能是显而易见的,但这是我第一次这样做,所以我想我会与其他新手分享迷你步骤。当然,也可以采用更清洁的方式。

#1


If you put the following two lines:

如果你把以下两行:

import pdb
pdb.set_trace()

Python will import the Python De Bugger and you will be in the interactive interpreter at this point in the code. It will evaluate all your Python expressions normally.

Python将导入Python De Bugger,您将在代码中的此处进入交互式解释器。它会正常评估所有Python表达式。

The most important commands are:

最重要的命令是:

  1. s - step (forward one command)
  2. s - 步骤(转发一个命令)

  3. c - continue (done)
  4. c - 继续(完成)

For a full list, see this: http://infohost.nmt.edu/tcc/help/pubs/python22/pdb-commands.html

有关完整列表,请参阅:http://infohost.nmt.edu/tcc/help/pubs/python22/pdb-commands.html

#2


Have a look at the pdb module. I have just barely learned about it, and played with it a bit. It appears to enable command line debugging by allowing you to set traces within the code. This gives you interactive access to your variables and code while it is running. Not quite the same as running the IDLE debugger with breakpoints, but it may work for you.
See this or this for more details.

Something else to look at ... under Options -> Configure IDLE -> Keys, there may be a way to map keystrokes to the action of setting a breakpoint.

看看pdb模块。我刚刚学会了它,并且玩了一下。它似乎允许您在代码中设置跟踪来启用命令行调试。这使您可以在变量和代码运行时以交互方式访问它们。与使用断点运行IDLE调试器不完全相同,但它可能适合您。有关详细信息,请参阅此或此内容。要查看的其他内容...在选项 - >配置IDLE - >键下,可能有一种方法可以将击键映射到设置断点的操作。

#3


It's a bug in IDLE, specifically any IDLE on Mac OS X linked with the default Aqua Tk, supplied with Mac OS X or from ActiveState. That includes the Apple-supplied Pythons in OS X 10.4 through 10.6 and the python.org installers. The problem is that Aqua Tk has a different mapping for mouse clicks and, even if that were fixed, IDLE expects users to always have a multi-button mouse. See Issue 10404 for more details and a patch. This should not be an issue if the Python is linked with an X11-based Tk, as is the default with MacPorts.

这是IDLE中的一个错误,特别是Mac OS X上与Mac OS X或ActiveState提供的默认Aqua Tk链接的任何IDLE。这包括OS X 10.4到10.6中Apple提供的Pythons和python.org安装程序。问题是Aqua Tk有一个不同的鼠标点击映射,即使修复了它,IDLE也希望用户总是有一个多键鼠标。有关更多详细信息和修补程序,请参见问题10404。如果Python与基于X11的Tk链接,这应该不是问题,这是MacPorts的默认设置。

#4


So, for newbies, a little more detail on Ned Deily's patch. Here is what I did. I'm running python 2.7.1 in idle on osx 10.6.5. I followed Ned's link for Issue 10404, and finally to the patched version of the file EditorWindow.py, which on my installation lives in the directory

所以,对于新手来说,更多关于Ned Deily补丁的细节。这就是我做的。我在osx 10.6.5上空闲运行python 2.7.1。我按照Ned的问题10404的链接,最后到了EditWindow.py文件的修补版本,我的安装文件位于目录中

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/idlelib

Following more links, we find the patched version of the file is here.

下面是更多链接,我们发现文件的修补版本在这里。

This you can download from the "raw" link to the left on that page. Keep a copy of your old version of EditorWindow.py, then move or copy the new EditorWindow.py from your Download directory to the idlelib directory. Restart idle, and ctrl-click gives drop-down menus for setting breakpoints. This is probably all obvious, but it's the first time I did it so I thought I'd share the mini-steps with other novices. There may be a cleaner way to do it too of course.

您可以从该页面左侧的“原始”链接下载。保留旧版EditorWindow.py的副本,然后将新的EditorWindow.py从Download目录移动或复制到idlelib目录。重新启动空闲,然后按住ctrl-click提供设置断点的下拉菜单。这可能是显而易见的,但这是我第一次这样做,所以我想我会与其他新手分享迷你步骤。当然,也可以采用更清洁的方式。