1. 環境:
系統環境:win7
軟件環境:pycharm 3.1.1
2. 將client端(實際程序執行的環境)的代碼所在的路徑映射到server端(IDE):
Remote path-代碼所在的client端路徑是:/home/lovecat/branches/transcoder2.0/src/transcoder/src
Local path-映射到本地server端的路徑是:N:/branches/transcoder2.0/src/transcoder/src
3. 在server端(IDE)和client端(實際程序執行的環境)都安裝上 pycharm-debug.egg:
pycharm-debug.egg在server端pycharm安裝目錄下
安裝命令:
easy_install pycharm-debug.egg
4. 配置server端:
4.1 打開Edit confiurations
4.2 新增一個python remote debug配置:
Local Host Name:server端的ip地址
Port:任意一個不和其他程序衝突的端口
Path Mappings:server端和client端代碼所在路徑的映射
Local path:參考 【2-Local path】
Remote path:參考 【2-Remote path】
5. 配置client端:
在需要調試的代碼開頭加上以下代碼:
host:server端的ip地址,參考【4-Local Host Name】
port:server端設置的調試環境的端口,參考【4-Port】
stdoutToServer:when this is true, the stdout is passed to the debug server
stderrToServer:when this is true, the stderr is passed to the debug server
import pydevd
pydevd.settrace(host='192.168.1.203', port=2315, stdoutToServer=True, stderrToServer=True)
6. 啓動調試環境:
6.1 啓動server端:
6.2 啓動client端:
client端啓動成功後,server端會有如下輸出:
7. 調試:
在server端映射的代碼打上斷點即可進行調試