Teach you how to connect to cloud resources in PyCharm for code debugging

Abstract: ModelArts provides a PyCharm plug-in tool, PyCharm ToolKit, to assist users in uploading code, submitting training jobs, obtaining training logs for local display, etc. Users only need to focus on local code development.

This article is shared from Huawei Cloud Community " Teach you how to connect to cloud resources in PyCharm for code debugging ", author: Hello EI.

ModelArts provides a PyCharm plug-in tool, PyCharm ToolKit, to assist users in uploading code, submitting training jobs, and obtaining training logs for local display, etc. Users only need to focus on local code development.

Let's see how to connect to cloud resources in PyCharm for code debugging!

Only the professional version of PyCharm supports the remote development function, please ensure that the 2019.2 and above version of PyCharm professional version is installed locally.

Overview of steps

  • Step1 Install PyCharm ToolKit
  • Step2 Create plugin access key
  • Step3 Create a Notebook instance
  • Step4 plug-in automation configuration
  • Step5 Use the plug-in to connect to the Notebook on the cloud
  • Step6 Upload local files to Notebook synchronously
  • Step7 remote debugging

Step1 Install PyCharm ToolKit

Select "File > Settings > Plugins" in PyCharm, search for "ModelArts" in the Marketplace, and click "Install" to complete the installation.

Step2 Create plugin access key

Create plugin access keys (AK and SK) (reference link) .

Step3 Create a Notebook instance

Create a Notebook instance in the ModelArts console. When creating, you need to enable remote SSH development and select a key pair, and ensure that the instance is in the "Running" state.

Please download the created key pair and keep it safe. When using PyCharm to remotely connect to the Notebook development environment on the cloud, you need to use the key pair for authentication.

Step4 plug-in automation configuration

Only the professional version of PyCharm supports the remote development function, please ensure that the 2019.2 and above version of PyCharm professional version is installed locally.

1. Select "ModelArts > Edit Credential" in the PyCharm menu bar.

2. Input the created access key (AK and SK) into the corresponding position of ToolKit, click the OK button to log in, and the following prompt appears, which means the login is successful.

3. Select "ModelArts > Notebook > Remote Config" in the PyCharm menu bar, select the Notebook instance to be connected in the opened interface, and select the key corresponding to the Notebook instance in KeyPair.

  • KeyPair: You need to select the keypair authentication corresponding to the Notebook saved locally. That is, the key pair file created when creating a Notebook will be directly saved to the default download folder of the browser when created.
  • PathMappings: This parameter is the synchronization directory corresponding to the PyCharm project and Notebook. The default name is "/home/ma-user/work/project", which can be changed according to your actual situation.

Step5 Use the plug-in to connect to the Notebook on the cloud

When the Notebook instance is in the green triangle state (below), it means that the instance is running (but not connected to PyCharm). Click the instance name at this time, and the instance will turn into a green tick state, indicating that PyCharm has successfully connected to the instance.

Step6 Upload local files to Notebook synchronously

  • Initialize synchronization
    In the Project directory of PyCharm, right-click, select "Deployment", click "Upload to xxx" (Notebook name), and upload the local project file to the specified Notebook.
  • Subsequent synchronization
    Just modify the code and save (ctrl+s) to perform automatic synchronization.
    After the plug-in is installed, enable "Automatic Upload" in PyCharm, and the files in the local directory will be automatically uploaded to the cloud development environment Notebook. If it is not enabled, click "Tool > Deployment > Automatic Upload".

Step7 remote debugging

1. Select the Python interpreter

Method 1: Click the interpreter in the lower right corner of PyCharm, and select the Python interpreter of Notebook.

Method 2: Click the Edit Configuration button in the upper right corner of PyCharm to set the running parameters.

Choose to remotely connect to the Python interpreter corresponding to the development environment instance on the cloud.

2. Code debugging

When you need to debug the code, you can directly break the point, and then use the debug mode to run the program.

 

Click to follow and learn about Huawei Cloud's fresh technologies for the first time~

{{o.name}}
{{m.name}}

おすすめ

転載: my.oschina.net/u/4526289/blog/5988399