Remote Debugging with PyCharm Professional
Introduction
In this tutorial, you can learn how to set up remote debugging with PyCharm Professional on the platform using the flow template.
Remote debugging relies on a running SSH server in a job's 22 port. We ensure it for you if you use our base image (ghcr.io/neuro-inc/base
).
Initializing a new flow
First, make sure that you have the Apolo CLI client and cookiecutter installed and configured, refer to https://github.com/neuro-inc/platform-docs/blob/master/apolo-console/first-steps/getting-started.md#installing-the-cli
Then, initialize a new flow:
This command will prompt you to enter some info about your flow:
Next, switch to the new project's folder and configure the project's environment on the Platform:
Setting up PyCharm
Open the project you have just created in PyCharm Professional and add the code you want to debug as a new main.py
file (in this example, we use a code snippet from the JetBrains documentation).
Then, you will need to exclude all directories that don't contain Python code (in an empty Apolo project, only the modules
folder will contain code). PyCharm doesn't synchronize excluded directories. Select all directories to exclude, right-click, and select Mark Directory as -> Excluded. As a result, you will see a configured project:
Run these commands to upload your code to the platform storage:
Now, we are ready to start a GPU-powered development job on the platform. Run the following command:
This command starts a remote_debug
job on the platform. This job uses the user's default preset and forwards the local port 2211 to the job's SSH port. All running jobs consume your quota, so please don't forget to terminate your jobs when they are no longer needed. You can use apolo-flow kill remote_debug
to kill the job you created in the previous step or apolo-flow kill ALL
to kill all your running jobs.
Then go back to the PyCharm project and navigate to Preferences -> Project -> Project interpreter (you can also search for "interpreter"). Click the gear icon to view the project interpreter options and select Add... In the new window, select SSH Interpreter and set up the following configuration:
Host: localhost
Port: 2211
Username: root
When this is done, click Next.
In the new window, specify the paths for the interpreter and synced folders:
Note that, within the job, your project's root folder is available at the root of the filesystem: /{project_name}
.
Click Finish, and your configuration is ready:
Click OK.
Once you apply the remote interpreter configuration, PyCharm will start file synchronization.
Your PyCharm project is now configured to work with a remote Python interpreter running in a job.
Debugging
In this example, we're working with the main.py
file. To enter debug mode, right-click the file and click Debug 'main':
Now, you can interact with the file in debug mode:
If your project's mapping was not configured and the remote interpreter attempts to execute a file with a local path on the remote environment, you might need to specify the path mappings. You can do that at Run -> Edit Configurations... -> Path mappings:
Last updated