Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Manually Connecting to a Notebook Instance Through PyCharm

Updated on 2024-10-29 GMT+08:00

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 PyCharm to access a notebook instance.

Prerequisites

  • PyCharm professional 2019.2 or later has been installed locally. The PyCharm professional edition is available because remote SSH applies only to the professional edition.
  • 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 this 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 Configure SSH

  1. In your local PyCharm development environment, choose File > Settings > Tools > SSH Configurations and click + to add an SSH configuration.
    • Host: 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 name: consistently set to ma-user.
    • Authentication type: key pair
    • Private key file: locally stored private key file of the cloud development environment. It is the key pair file automatically downloaded when you created the notebook instance.
  2. Click to rename the connection. Then, click OK.
  3. After the configuration is complete, click Test Connection to test the connectivity.
  4. Select Yes. If "Successfully connected" is displayed, the network is accessible. Then, click OK.
  5. Click OK at the bottom to save the configuration.
Figure 2 Configuring SSH

Step 2 Obtain the Path to the Virtual Environment Built in the Development Environment

  1. Choose Tools > Start SSH Session to access the cloud development environment.
  2. Run the following command to view the Python virtual environments built in the current environment in the README file in /home/ma-user/:
    cat /home/ma-user/README
  3. Run the source command to switch to a specific Python environment.
  4. Run which python to obtain the Python path and copy it for configuring the Python interpreter on the cloud.
Figure 3 Obtaining the path to the virtual environment built in the development environment

Step 3 Configure a Python Interpreter

  1. Choose File > Settings > Project: Python project > Python Interpreter. Then, click and Add to add an interpreter.
  2. Select Existing server configuration, choose the SSH configuration from the drop-down list, and click Next.
  3. Configure the Python interpreter.
    • Interpreter: Enter the Python path copied in step 1, for example, /home/ma-user/anaconda3/envs/Pytorch-1.0.0/bin/python.

      If the path is ~/anaconda3/envs/Pytorch-1.0.0/bin/python, replace ~ with /home/ma-user.

    • Sync folders: Set this parameter to a directory in the cloud development environment for synchronizing local project directory files. A directory in /home/ma-user is recommended, for example, /home/ma-user/work/projects, because other directories may be prohibited from accessing.
  4. Click ! on the right and select Automatically upload so that the locally modified file can be automatically uploaded to the container.
  5. Click Finish.

    The local project file has been automatically uploaded to the cloud environment. Each time a local file is modified, the modification is automatically synchronized to the cloud environment.

    In the lower right corner, the current interpreter is displayed as a remote interpreter.

    Figure 4 Configuring a Python interpreter

Step 4 Install the Dependent Library for the Cloud Environment

After accessing the development 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.

Choose Tools > Start SSH Session and select the configured development environment. Run the pip install command to install the required dependency packages.

Step 5 Debug Code in the Development Environment

You have accessed the cloud development environment. Then, you can write, debug, and run the code in the local PyCharm. The code is actually executed in the cloud development environment, and the Ascend AI resources on the cloud are used. In this way, you compile and modify code locally and run the code in the cloud.

Run the code in the local IDE. The logs can be displayed locally.

Figure 5 Debugging code

Click Run/Debug Configurations in the upper right corner of the local IDE to set runtime parameters.

Figure 6 Setting runtime parameters

To debug code, set breakpoints and run the program in debug mode.

Figure 7 Code breakpoint
Figure 8 Debugging in debug mode

In debug mode, the code execution is suspended in the specified line, and you can obtain variable values.

Figure 9 Debug mode

Before debugging code in debug mode, ensure that the local code is the same as the cloud code. If they are different, the line where a breakpoint is added locally may be different from the line of the cloud code, leading to errors.

When configuring a Python interpreter in the cloud development environment, select Automatically upload so that any local file modification can be automatically uploaded to the cloud. If you do not select Automatically upload, manually upload the directory or code after you modify the local code. For details, see Step 6 Uploading Local Files to a Notebook Instance.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback