我正在尝试运行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
然后:
(tempenv)$ python -m pdb -c continue foo.py
Error: -c does not exist
将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?即使我使用virtualenv --no-site-packages
重试,它仍然显示相同的路径):
(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)
答案 0 :(得分:2)
您使用的是Python 2.7,doesn't support the -c
parameter:
3.2版中的新功能:
pdb.py
现在接受一个执行命令的-c选项,就像在.pdbrc
文件中一样,请参阅Debugger Commands。
通过将Python升级到版本3.6可以解决问题。
我没有在PyPI上找到任何将3.2+ pdb
包反向移植到Python 2.7的包。 The one you were trying to install是“密码数据库”。