Manually Connecting to a Notebook Instance Through VS Code
A local IDE supports PyCharm and VS Code. You can use PyCharm or VS Code to remotely connect the local IDE to the target notebook instance on ModelArts for running and debugging code.
This section describes how to use VS Code to access a notebook instance.
Prerequisites
- You have downloaded and installed VS Code. For details, see Installing VS Code.
- Python has been installed on your local PC or server. For details, see VS Code official documentation.
- A notebook instance has been created with remote SSH enabled. Ensure that the instance is running. For details, see Creating a Notebook Instance.
- The address and port number of the development environment are available. To obtain the information, go to the notebook instance details page.
Figure 1 Instance details page
- The key pair is available.
A key pair is automatically downloaded after you create it. Securely store your key pair. If an existing key pair is lost, create a new one.
Step 1 Add the Remote-SSH Plug-in
In the local VS Code development environment, click , enter SSH in the search box, and click install of the Remote-SSH plug-in to install the plug-in.
Step 2 Configure SSH
- In the local VS Code development environment, click on the left, select SSH Targets from the drop-down list box, and click . The SSH configuration file path is displayed.
Figure 3 Configuring SSH Targets
- Click the SSH configuration path and configure SSH.
Figure 4 SSH configuration file path
HOST remote-dev hostname <Instance connection host> port <Instance connection port> user ma-user IdentityFile ~/.ssh/test.pem UserKnownHostsFile=/dev/null StrictHostKeyChecking no
- HOST: name of the cloud development environment
- HostName: address for accessing the cloud development environment. Obtain the address on the page providing detailed information of the target notebook instance.
- Port: port number for accessing the cloud development environment. Obtain the port number on the page providing detailed information of the target notebook instance.
- user: ma-user
- IdentityFile: locally stored private key file of the cloud development environment. It is the key pair file in Prerequisites.
- Choose File > Preference > Settings > Extensions > Remote-SSH. On the Remote Platform page, click Add Item, set Item and Value, and click OK.
Figure 5 Configuring Remote Platform
Item: host name configured in SSH configuration
Value: remote development environment platform
- Go back to the SSH Targets page and click on the right. Then, click the development environment name to open the development environment.
Figure 6 Opening the development environment
After the page shown in the following figure is displayed, the connection is succeeded.
Figure 7 Remote connection succeeded
Figure 8 Complete configuration example
Step 3 Install the Python Plug-in in the Cloud Development Environment
On the displayed VS Code page, click on the left, enter Python in the search box, and click Install.
If the Python plug-in fails to be installed on the cloud, install it using an offline package.
Step 4 Install the Dependent Library for the Cloud Environment
After accessing the container environment, you can use different virtual environments, such as TensorFlow and PyTorch. However, in actual development, you need to install dependency packages. Then, you can access the environment through the terminal to perform operations.
- In VS Code, press Ctrl+Shift+P.
- Search for Python: Select Interpreter and select the target Python.
- Choose . The CLI of the remote container is displayed.
- Run the following command to install the dependency package:
pip install spacy
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot