macOS High Sierra上找不到Python调试器pdb

9

根据PythonDebuggingTools文档,Python调试器pdb是“所有Python安装的一部分”,但我在macOS High Sierra下无法找到它:

pdb: command not found

这些天在macOS中是否应该将其安装为常规部分?
2个回答

17

没有名为pdb的命令,但你可以在shell中使用以下方式调用pdb:

python -m pdb your_script.py

您可以在pdb文档中阅读更多使用方法。


0
如果您使用IPython,可以通过以下方式调用调试器:
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %pdb
Automatic pdb calling has been turned ON

In [2]: %pdb
Automatic pdb calling has been turned OFF

In [3]: ?pdb
Docstring:
Control the automatic calling of the pdb interactive debugger.

Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
argument it works as a toggle.

When an exception is triggered, IPython can optionally call the
interactive pdb debugger after the traceback printout. %pdb toggles
this feature on and off.

The initial state of this feature is set in your configuration
file (the option is ``InteractiveShell.pdb``).

If you want to just activate the debugger AFTER an exception has fired,
without having to type '%pdb on' and rerunning your code, you can use
the %debug magic.
File:      ~/anaconda/envs/py36/lib/python3.6/site-packages/IPython/core/magics/execution.py

您可能需要使用pip或conda安装IPython。


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