How remote debugging in PyCharm

The problem I'm facing right now:

  • I am deploying Python code to a remote host via SSH
  • scripts are passed some arguments and must be run by a specific user
  • PyCharm's launch / debug configuration that I create connects via SSH through another user (cannot connect to the user who actually runs the scripts)
  • I want to remotely debug this code through PyCharm ... I was able to complete the entire configuration, I just got permission errors.

Are there any ways to run / debug scripts as a specific user (e.g. sudo su - user)?

I read about specifying some Python Interpeter options in the configuration of the PyCharm remote / debugging device, but failed to get a working solution.

+5
source share
1 answer

If you need a simpler and more flexible way to get into the PyCharm debugger, rather than having to have a โ€œplayโ€ button with one click in PyCharm, you can use the debug server functionality. I used this in situations where running some Python code is not as simple as running python ...

See the Remote Dython Docs Debugging File for Python for more details, but here is a brief description of how this works:

  • Download and install the remote debugging helper egg on your server (in OSX they are found under /Applications/PyCharm.app/Contents/debug-eggs )
  • Configuring the remote debug server: click on the configuration menu of the drop-down menu, select Edit configurations... , click the + button, select Python remote debug .
    • The details entered here (somewhat vaguely) tell the remote server running the Python script how to connect to your laptop's PyCharm instance.
    • set Local host name to the IP address of your laptop.
    • install port on any free port that you can use on your laptop (for example, 8888 )
  • Now follow the remaining instructions in this dialog: copy-paste the import and pydevd.settrace(...) into your code, in particular where you want your code to โ€œhit a breakpointโ€. This is basically the equivalent of PyCharm import pdb; pdb.set_trace() import pdb; pdb.set_trace() . Make sure that the changed code is synchronized with your server.
  • Click the error button (next to the game, this will start the PyCharm debug server) and run the Python script in the same way as you usually did in any user environment, etc. When the breakpoint hits, PyCharm should go into debug mode.
+8
source

Source: https://habr.com/ru/post/1244287/


All Articles