1

I'm trying to run python -m pdb -c continue foo.py, in order to enable debugging upon errors. The -c continue arguments should allow me to do this without specifying 'c' upon program start. However, I receive the error: Error: -c does not exist. I will demonstrate the versions and setup below with a virtualenv example.

$ 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

Then:

(tempenv)$ python -m pdb -c continue foo.py
Error: -c does not exist

After installing pdb locally into the 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

Running without -c continue works fine (although I'm surprised to see it using /usr/lib/python2.7/pdb.py instead of the local pdb? even when I retried with virtualenv --no-site-packages, it still showed that same path):

(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) 
Community
  • 1
  • 1
eqzx
  • 5,323
  • 4
  • 37
  • 54

1 Answers1

2

You are using Python 2.7, which doesn't support the -c 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.

By upgrading your Python to version 3.6 would solve the problem.

I didn't find any package on PyPI that backports the 3.2+ pdb package to Python 2.7. The one you were trying to install is a "password database".

Philip Tzou
  • 5,926
  • 2
  • 18
  • 27
  • also, [virtualenv](https://github.com/pypa/virtualenv/blob/master/virtualenv.py) per se doesn't seem to transfer "pdb" (not in the `REQUIRED_MODULES` list) – ewcz Apr 10 '17 at 17:06
  • I see. Any suggestions for how I could modify `pdb.py` to continue anyway? I want to make continuing the default behavior in Python 2.7 – eqzx Apr 10 '17 at 18:27
  • 1
    @eqzx: I modified this from Python 3.5: https://gist.github.com/philiptzou/dbfbf727ad7127c8f276d312790eac9f. It seems working with my Python 2.7. You can put the `pdb.py` file in the same folder with the file to be debugged and run the command. – Philip Tzou Apr 12 '17 at 03:49