Python pdb in python script works like a package

I have a python program that I usually run as part of a package:

python -m mymod.client 

to deal with relative imports inside "mymod / client.py". How to run this with pdb - python debugger. The following does not work:

 python -m pdb mymod.client 

Gives an error message:

 Error: mymod.client does not exist 

EDIT No. 1 (to eliminate the possible duplicity of the question)

My question is not to run two python modules at the same time, but how to use pdb on a python script that has relative imports inside it and which usually deals with running a script with "python -m."

Repeatedly, then the question may arise how to use pdb for such a script without changing the script itself so that it starts with pdb (i.e. keeping the relative import inside the script as much as possible). Isn't that possible, or am I forced to somehow reorganize if I want to use pdb? If so, what would be the minimal changes to the script structure that I would have to introduce to allow me to use pdb.

In general, I don't care how I run the script, only if I can get it to work with pdb without changing its internal structure (relative import, etc.) too much.

+7
python pdb python-module
source share
2 answers

I think I have a solution.

Run it as follows:

 python -m pdb path/mymod/client.py arg1 arg2 

which will run it as a script, but will not treat it as a package. At the top of client.py, the first line should be:

 import mymod 

This will download the package itself. I am still playing with this, but it seems to be working so far.

+1
source share

It's impossible. Although not specified in the documentation, Python will not parse the two modules using the -m command line.

0
source share

All Articles