To configure a remote debug server

Specify the local host name and the number of the port where the debug server will run. If you don't specify any value, PyCharm will provide port number at random.

If you are going to debug a script that resides on a remote machine, specify the source root of the remote script, and the root of the local sources to keep mapping.

To prepare for remote debugging

In PyCharm, open the local script for editing, and add the following command (you can copy it from the remote debug configuration dialog):

pydevd.settrace(<host name>, port=<port number>)

Also, add the corresponding import statement to your script:

import pydevd

Copy the local script to the remote location, where you want to debug it.

Include the pycharm-debug.egg archive. You can do it in a number of ways, for example:

Add the archive to PYTHONPATH.

Append the archive to sys.path.

Just copy the pydev from the archive to the directory where your remote script resides.

To launch the debug server

Select the desired remote configuration:

Click , or press Shift+F9. PyCharm launches debug server at the specified host and port, which is shown in the Console pane of the Debug tool window.

If the process doesn't stop, but you still want to stop tracing and disconnect from Python Remote Debug Server, add the following function to the end of a remote script being debugged:

pydevd.stoptrace()

This function stops remote debug process that has been launched with pydevd.settrace(). Thus the Python Remote Debug Server will pass to the state of waiting for a new connection.

To debug a remote script

Locate your remote script, and launch it as required by your specific operating system. For example, on Windows, use the command:

python <script name>

If the corresponding local script exists, PyCharm opens it in the editor in the suspended mode; the first executable statement is marked with the blue stripe. Also, PyCharm shows the frames and variables for its first executable statement in the Debug tool window. If the corresponding local script cannot be found, PyCharm opens a dedicated editor tab, and suggests you to do one of the following:

Edit the local and remote roots in the remote debug configuration dialog box.

Detect the mapping files automatically, and then select the one to be used as the local version from the list of encountered files with the matching names.