无法理解python m pdb c continue标志参数

2024-05-16 22:42:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图运行python -m pdb -c continue foo.py,以便在出错时进行调试。程序启动时,-c continue参数应allow me to do this,而不指定“c”。但是,我收到错误:Error: -c does not exist。我将用一个virtualenv示例演示下面的版本和设置。在

$ virtualenv --version
15.1.0
$ virtualenv tempenv
New python executable in tempenv/bin/python
Installing setuptools, pip...done.
$ source tempenv/bin/activate
(tempenv)$ which python
/usr0/home/eqzx/tempenv/bin/python
(tempenv)$ python --version
Python 2.7.6
(tempenv)$ echo "1/0" > foo.py
(tempenv)$ python foo.py
Traceback (most recent call last):
  File "foo.py", line 1, in <module>
    1/0
ZeroDivisionError: integer division or modulo by zero

然后:

^{pr2}$

在将pdb本地安装到virtualenv后:

(tempenv)$ pip install -I pdb
(tempenv)$ which pdb
/usr0/home/eqzx/tempenv/bin/pdb
(tempenv)$ python -m pdb -c continue foo.py
Error: -c does not exist

不使用-c continue运行很好(尽管我很惊讶地看到它使用/usr/lib/python2.7/pdb.py而不是本地pdb?{cd7>,即使在cd7}显示相同的路径时):

(tempenv)$ python -m pdb foo.py
> /usr0/home/eqzx/foo.py(1)<module>()
-> 1/0
(Pdb) c
Traceback (most recent call last):
  File "/usr/lib/python2.7/pdb.py", line 1314, in main
    pdb._runscript(mainpyfile)
  File "/usr/lib/python2.7/pdb.py", line 1233, in _runscript
    self.run(statement)
  File "/usr/lib/python2.7/bdb.py", line 400, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "foo.py", line 1, in <module>
    1/0
ZeroDivisionError: integer division or modulo by zero
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr0/home/eqzx/foo.py(1)<module>()
-> 1/0
(Pdb) 

Tags: inpyhomebinvirtualenvfoousrline
1条回答
网友
1楼 · 发布于 2024-05-16 22:42:02

您使用的是Python2.7,doesn't support the ^{} parameter

New in version 3.2: pdb.py now accepts a -c option that executes commands as if given in a .pdbrc file, see Debugger Commands.

将Python升级到3.6版可以解决这个问题。在

我在PyPI上找不到任何将3.2+pdb包向后移植到python2.7的包。The one you were trying to install是一个“密码数据库”。在

相关问题 更多 >