Debugging Remotely with PyCharm: Step to Step Tutorial

This tutorial is designed for students in COMP SCI540: Intro to AI at the University of Wisconsin-Madison.

But if you have SSH access to a remote server, this tutorial can also help you to configure a python interpreter and debug remotely.

Why remote debugging with PyCharm?

Comparing to the python debugger pdb, the debugger in PyCharm provides a visual interface and allows watches, which are way more intuitive and user-friendly.

Before you start

Configure a remote interpreter

1. Go to Settings -> Project -> Python Interpreter. Click on the setting icon -> Click on the Add option.

2. In the Add Python Interpreter window, go to SSH Interpreter. Choose Existing server configuration. Choose your SSH configuration. (If you don’t have one, see my previous tutorial)

3. Click on Next (Notice: you might be asked to make your SSH configuration globally before continuing)

4. In CSL machines, the default interpreter is

/usr/bin/python

If you want to run version 3.8, change the Interpreter to

/usr/bin/python3.8

*If you want to use a virtual environment, make sure you change the Interpreter to the one in your virtual environment, for example:

/u/k/a/kaiw/Pytorch/bin/python3

Modify the Sync folders by clicking on the folder button on the right.

Modify your Local Path and Remote Path (Warning: double-check you don’t have extra spaces in the path). An example:

Click on OK. You don’t need to check the box of Automatically upload if you did this before in the Deployment configurations.

Click on Finish.

5. Test the debugger

  • Choose the Python Interpreter you have just created (You can always change the interpreter back to the one on your local machine).
  • You can see this file has been automatically uploaded to CSL machines
  • Right-click and select Debug ‘test_debugger’
  • If the debugger stops at your breakpoint, you have successfully configured the remote debugging in PyCharm

Congrats! You can now debug remotely in PyCharm. If you have any questions or thoughts, feel free to comment below or contact me.

See also:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kai Wang

undergraduate computer science major at the University of Wisconsin-Madison