SoFunction
Updated on 2024-11-17

Pycharm connects to a remote server and implements a remote debugging implementation

Using pycharm to connect to a server remotely is necessary when working remotely.
PyCharm provides two ways of Remote Debugging.

  1. Configuring the remote interpreter
  2. Configuring the Python Debug Server (Python Debug Server)

This post focuses on configuring the remote interpreter, and a brief introduction to configuring the python debugging server is also provided at the end of the article.

1. Pycharm connects to a remote server

1.1 Access to the configuration page

Pycharm menu bar, as shown below, click Tools -> Deployment -> Configration...

1.2 Configuring the Connection Server

As shown in the figure below. name can be written randomly.

Connection, the protocol is best to choose sftp, next fill in the server host IP, user name, password.

Click on Test SFTP connection and you will find that if the connection is successful you will be prompted as follows

Under Mapping, choose to connect the windows part of the code and the server code connected to the local Local path, server path, apply, OK, that is, the local code and the server code has been connected.

1.3 Uploading code to synchronize local code with server code

Click Upload to name (the name of the remote server you just filled in) to upload the code.

If there are multiple different servers configured or multiple server upload paths (Deployment Path) configured for the same server, you can select Upload to... to upload to different servers/paths.

2. Configuring the remote Python interpreter

The prerequisite for using the server to debug Python programs is that the Python interpreter is installed on the server, if not, please install it first.

2.1 Setting the Python interpreter on a remote server

In the menu bar, File -> Settings... -> Project ×× -> Project Interpreter, click the Add button on the right to add the interpreter.

Select SSH Interpreter, fill in the server's Host address, port Port, username Username, fill in, Next Next.

Fill in the password Password, next Next.

Select the location of the Python interpreter on the remote server, the remote synchronization folder Sync folders on the server, and you can select more than one. If you do not know where Python is installed, you can use the command which python to find the Python installation location after connecting to the server remotely.

Finish, the configuration is finished. The project is now using the Python interpreter on the remote server. If you want to use this interpreter for future projects, just change the interpreter manually.

3. Running a local Python program using a remote interpreter

  1. Upload the test code to the remote server (Tools -> Deployment -> Upload to ××).
  2. Run the test code and you can see that the code is now running on the remote server.

This is the whole content of this article.