Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python debugger (pdb) stopped handlying up/down arrows, shows ^[[A instead

I am using python 2.6 in a virtualenv on an Ubuntu Linux 11.04 (natty) machine. I have this code in my (django) python code:

import pdb ; pdb.set_trace() 

in order to launch the python debugger (pdb).

Up until today, this worked fine. But now when the pdb starts, it works for debugging and running and breakpoints etc, but when I press the up arrow to show the previous command it prints ^[[A instead an doesn't go up. When I type something and press Home, it prints ^[OH instead of moving the cursor.

I can use up/home/etc. fine in the bash terminal which launches my python django unittests (which has the pdb call).

What's going on? How do I fix my pdb? What's wrong with my readline?

like image 930
Amandasaurus Avatar asked Apr 13 '12 11:04

Amandasaurus


People also ask

How do I use pdb debugger in Python?

Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().

How do I stop pdb debugging?

To start execution, you use the continue or c command. If the program executes successfully, you will be taken back to the (Pdb) prompt where you can restart the execution again. At this point, you can use quit / q or Ctrl+D to exit the debugger.

How do you get out of a loop in pdb?

Once you get you pdb prompt . Just hit n (next) 10 times to exit the loop.

How do you set a breakpoint in Python pdb?

Just use python -m pdb <your_script>. py then b <line_number> to set the breakpoint at chosen line number (no function parentheses). Hit c to continue to your breakpoint. You can see all your breakpoints using b command by itself.


2 Answers

Looks like from some reason you are missing the readline package. Simply install it by typing pip install readline and it should behave as expected. Remember to type it as superuser if you're not in venv.

like image 182
Tomasz Szymański Avatar answered Oct 02 '22 00:10

Tomasz Szymański


I found this problem exists when outputting to both console and file using python file.py 2>&1 | tee output.txt:

How to redirect stdout to both file and console with scripting?

After removing 2>&1 | tee output.txt, this problem (up arrow becomes ^[[A in pdb) disappear.

like image 32
Xueqing Liu Avatar answered Oct 02 '22 02:10

Xueqing Liu