ipdb
ipdb copied to clipboard
RuntimeWarning: 'ipdb.__main__' found in sys.modules after import of package 'ipdb', but prior to execution of 'ipdb.__main__'; this may result in unpredictable behaviour warn(RuntimeWarning(msg))
My command is : python -m ipdb test.py
and I got:
/root/.miniconda3/lib/python3.6/runpy.py:125: RuntimeWarning: 'ipdb.__main__' found in sys.modules after import of package 'ipdb', but prior to execution of 'ipdb.__main__'; this may result in unpredictable behaviour
warn(RuntimeWarning(msg))
What does this mean and how do I fix it? Thank you! ps: ipdb version 0.13.5
@alayamanas If this is possible on your system, try running ipdb directly:
ipdb3 test.py
Since several others (over 1000 reported views) have run into this as well, it might be worth fixing.
Some background
- In Python 3, when you run
python -m
it first imports the module (runs__init__.py
) and then__main__.py
directly. - There is no easy way to tell in
__init__.py
whether ipdb was run with the-m
flag.
Two possible solutions
- Do as many other libraries: move most of the main logic into a new file, e.g.
ipdb.py
and import from there, both in__init__.py
and also in__main__.py
. - Move most of the logic and
main()
function into__init__.py
and import main from__main__.py
.
What do you think @gotcha?
@mikez would you point me to one of those libraries ? It woule help me understand point 2 in your proposal.
A PR would be even better 😉
@gotcha The most important thing to understand is what python -m
does in Python3 (see my above post). After that, it boils down to moving most lines from __main__.py
to another file. Either to a new file (e.g. ipdb.py
) or to __init__.py
.
Hope that helps. For the solution (1) you can see most CLIs out there, for example flask or pip. The solution (2) I haven't seen in the wild I think, but it should work just as well. The important thing here is to understand what python -m
does.
@mikez Thanks for the clarification.