Pycharm远程调试

今天在工作中需要对一个利用bat文件运行的脚本进行调试,又不想直接通过Pycharm运行脚本。想到平时调试我们自己的游戏也不是直接在Pycharm运行的,应该可以从中借鉴思路。于是就搜索了一下方法,发现可以用Pycharm的远程调试功能实现。
想利用Pycharm的远程调试,需要做以下几点:

1.保证当前Pycharm的版本是professional

这个就不多说了,破解大法好

2. 在要运行的脚本初始写入远程调试代码:

def init_script_remote_debug():
    port_num = 10980
    pycharm_egg_path = "F:/Script/Python/share/pycharm-debug.egg"
    sys.path.append(pycharm_egg_path )
    import pydevd
    pydevd.settrace("localhost", port=port_num, stdoutToServer=True, stderrToServer=True, suspend=False)
    print "init script remote debug"

init_script_remote_debug()

其中端口号可以自己设定。pycharm-debug.egg是Pycharm为远程调试提供的辅助文件,默认存在于Pycharm目录下的pycharm-debug中。需要将它拷贝到pycharm_egg_path定义的位置。

3. :在Pycharm中载入脚本作为一个工程,并为工程配置远程调试

如图所示:

最后点击上方的debug按钮,在相应的地方打上断点,就可以直接运行bat脚本进行调试了!

原文地址:https://www.cnblogs.com/wickedpriest/p/12025034.html