-
Notifications
You must be signed in to change notification settings - Fork 482
Remote Debugging
Lex Berezhny edited this page Mar 9, 2018
·
1 revision
In PyCharm create a Python Remote Debugging
run configuration, it provides some instructions on what to do next. Here is a more detailed version of the next steps:
- Upload
pycharm-debug.egg
from$PYCHARM_INSTALL_DIR/debug-eggs/pycharm-debug.egg
up to the server. - Modify the source you want to debug by adding code for connecting to the debug server:
You can put this code anywhere in the project. It will act as the initial breakpoint and upon hitting this breakpoint it will try to connect to the debug server so that you can either continue stepping through code or continue the execution.
import sys sys.path.append('/PATH/TO/pycharm-debug.egg') import pydevd pydevd.settrace('localhost', port=1984)
- In order for the app to be able to connect to your local PyCharm instance you need to setup an ssh tunnel; you do this from your local machine. Map the port in the code above (eg,
1984
) to go into a tunnel and connect on the local port that the debugger is listening on (eg,8000
):ssh -R 1984:localhost:8000 [email protected]
- Last thing to do before debugging is to map the source directories between what they are on your local machine and on the remote server. This is so that as the debugger is stepping through the code you can actually see the code. You do this in the
Python Remote Debug
configuration in thePath mappings
section. - Set the port you want the debugger to listen on (eg,
8000
). - Once everything is setup and ready to go you want to start the debug server in PyCharm then after it's ready and listening for connections you can start the app on the server. Then just wait for the app to connect to PyCharm.