Intellij/Pycharm can't debug Python modules

前端 未结 4 1424
独厮守ぢ
独厮守ぢ 2020-12-30 01:56

I use PyCharm/IntelliJ community editions from a wile to write and debug Python scripts, but now I\'m trying to debug a Python modu

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 02:52

    I found it easiest to create a bootstrap file (debuglaunch.py) with the following contents.

    from {package} import {file with __main__}
    
    if __name__ == '__main__':
        {file with __main__}.main()
    

    For example, to launch locustio in the pycharm debugger, I created debuglaunch.py like this:

    from locust import main
    
    if __name__ == '__main__':
        main.main()
    

    And configured pycharm as follows.

    NOTE: I found I was not able to break into the debugger unless I added a breakpoint on main.main() . That may be specific to locustio, however.

提交回复
热议问题