Qun Gao
Qun Gao

Reputation: 19

pdb.set_trace() not working

When I insert import pdb; pdb.set_trace() in my code, it shows an error message:

'module' object has attribute 'set_trace'

In the pdb.py file, there is the def set_trace() function. How can it not work?

Has anyone had the same problem and knows how to solve this?

Upvotes: 1

Views: 4751

Answers (4)

MediaJ
MediaJ

Reputation: 61

if the python file that you are running is code.py please change the name. For some reasons code.py or pdb.py files can not use pdb package.

Upvotes: 3

DrStrangepork
DrStrangepork

Reputation: 3134

If your script is named pdb.py, that will cause this error. Change the name of your script.

Upvotes: 0

fr_andres
fr_andres

Reputation: 6677

What Python version are you using? I can reproduce that error if I try to import pdb; pdb.set_trace() on Python 3.8.

Try to use breakpoint() instead (has basically the same purpose), it worked for me!

Cheers,
Andres

Upvotes: 0

Nguyen Duc Hai
Nguyen Duc Hai

Reputation: 351

change the name file pdb.py same bdb_test.py it run with me

Upvotes: 0

Related Questions