当前位置:网站首页>Pycham connects to the remote server and realizes remote debugging

Pycham connects to the remote server and realizes remote debugging

2022-04-23 16:36:00 Sink the wine cup and fleeting time

Pycharm Connect to the remote server and realize remote debugging

Connect to remote server

1、 Click on Tools( Tools ), Click on Deploy Deployment( Deploy ), Click on Configuration( To configure )
 Insert picture description here

2、 Add a new one SFTP Link to agreement
 Insert picture description here

3、 Name the link
 Insert picture description here

4、 Configure server information

choice Connection tab page , Enter the remote server address 、 User name and password , Click on Test Connection( Test connection )
 Insert picture description here

If the pop-up connection is successful , Indicates that the connection to the remote server is configured successfully
 Insert picture description here

5、 Configure synchronization content

choice Mappings tab page , Configure the path where the local project is located and the path where the remote server project is located . In this way, as long as one party makes modifications , Code can be synchronized manually

 Insert picture description here

6、 Open at terminal SSH Connect

Click on Tools( Tools ), Click on Deploy Start SSH session

 Insert picture description here

Select the remote server to connect to

 Insert picture description here

If pycharm Of Terminal The terminal displays the corresponding server information , Indicates that the remote server is connected , It can be the same as in the server terminal , To operate

 Insert picture description here
Be careful : If pycharm Of Terminal Chinese garbled code appears on the terminal , Then it needs to be modified pycharm Of Tools To configure
Click on the top left corner FilesSettings , Click on Tools, Change the format to utf-8
 Insert picture description here

7、 View the remote server directory structure

Click on Tools( Tools ), Click on Deploy Deployment( Deploy ), Click on Browse Remote Host( Browse remote hosts )

 Insert picture description here

stay pycharm Of You can view the directory structure of the remote server on the right

 Insert picture description here

Synchronization code

Click on Tools( Tools ), Click on Deploy Deployment( Deploy )

  • If you want to synchronize your code to a remote server , Click on Upload to deepin(deepin Is the name of the remote host )

  • If you want to pull code from a remote server , The click Download from deepin(deepin Is the name of the remote host )

  • If I check that Automatic Upload (always), that , You modified the code locally ,pycharm The code will be automatically synchronized to the remote server ( This is not recommended in real projects , Will cause code conflicts , Of course , Will be used in real projects git. Your own private server doesn't matter )

 Insert picture description here

Configure the remote interpreter for debugging

In some cases , In the remote server ,python Some library versions of the interpreter are inconsistent with the local version , perhaps Windows Some libraries and Linux Some libraries under are different , It will cause the code to run normally locally , But running on the remote server is abnormal .
This situation , You can go to pycharm Configure... In the remote server in python Debug the interpreter

1、 Click on the top left corner FilesSettings , Click on Project Interpreter, Click on Add
 Insert picture description here
2、 choice SSH Interpreter, choice Existing server configuration, Select the remote server
 Insert picture description here

3、 To configure Python The path of the interpreter

In general , Selected Python The interpreter version is python3, Path is /usr/bin/python3
 Insert picture description here

If the virtual environment is also configured on the remote server , Then you can select the directory where the virtual environment is located python3 file

版权声明
本文为[Sink the wine cup and fleeting time]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231402128548.html