Python Remote Debugging

Source: Internet
Author: User

From:https://www.xncoding.com/2016/05/26/python/pycharm-remote.html

Do you often develop Python or Web applications on Windows 7 or Mac OS X, but they finally need to run on Linux? We often run into problems with development, but there is a problem with the formal Linux environment. So how do you ensure that the development environment is consistent with the operating environment?

There are usually two ways of solving this. One is built-in support using Pycharm Vagrant , which can be referenced in the Vagrant development environment configuration. However, it is very regrettable that I myself in the test process to start the VirtualBox virtual machine is always error, temporarily not resolved, the reader can try to test their own to see the line. The second way is to debug the test program through remote debug by using the Pycharm remote interpreter plus the file synchronization feature, which enables local edit code, sync to server. Now I'm choosing the second one, though more awkward than the first.

The function of remote debugging is supported in large Ides such as Eclipse, IntelliJ idea, and the principle of implementation is basically the same, which is illustrated by Pycharm.

Synchronization configuration for remote servers

Remote server IP address 192.168.203.95, open SSH service, install Python version 2.7. I use a Core-python project in Pycharm to do the demo.

First we need to configure code synchronization for the Pycharm server to open Tools | Deployment | Configuration

Click "+" on the left to add a deployment configuration, enter the name, type select SFTP

When you are sure, configure the remote server's IP, port, user name, and password. Root path is the root directory of the file upload, note that this directory must have user name permissions to create the file.

Then configure the map, local path is your project directory, you need to synchronize this directory to the server, I filled in the project root directory. Deploy path on server here to fill in the directory relative to the root path, the following Web path does not have to control the first

If you still have some files or folders that you do not want to sync, you can add them to the Third tab of the Configuration dialog box "excluded path", specifying both local and remote.

There is also a setting to open Tools | Deployment | Options, "Create Empty directories" Tick, if the specified folder does not exist, will be created automatically.

Uploading and downloading files

There are several ways to synchronize local and remote files, manually and automatically triggered when files are saved. Here I chose manual, because automatically trigger such as affect performance, Pycharm card, feel uncomfortable.

Manual upload is simple, select the files or folders you want to sync, then choose Tools | Deployment | Upload to SFTP (this is the deployment name you just configured)

The same is true for downloading files, selecting Tools | Deployment | Download from SFTP

Compare remote and local files

Sometimes you are not sure that the remote and local versions are exactly the same and need to be compared. Pycharm provides a contrasting view to solve this problem for you.

Select Tools | Deployment | Browse remote host, open the file view of remotely, and in the right window you can see the files on the remote hosts

Select a folder that you want to compare, right-click->sync with Local, open the Sync Comparison window, and use the left arrow to sync the content.

Above is the server and local comparison, then the local file-to-server comparison, first select the file or folder in Pycharm, and then right-->deployment->sync with deployed to can

Pycharm Remote Debugging

There are two options for remote debugging in Pycharm:

    1. Using the remote interpreter
    2. Debug a server with Python

For the sake of simplicity, I only demonstrate the first, using the remote interpreter, which is the Python interpreter installed on the server.

Configuring the remote Python Interpreter

Select File | Settings, choose Project | Project interpreter, then on the right, click on the pinion settings, as follows

Then click "Add Remote" to complete the SSH configuration of the host

If you have previously configured SFTP, then directly select "Deployment Configuration", and then choose just the template name can be, because I have configured the direct selection of templates, here please carefully see my Python interpreter is a virtual environment virtualenv, This is to create a virtual environment on the server first.

Start debugging

After completion, select this remote interpreter as the interpreter of the project, then configure a running instance, break point debugging. Here I take another Django project as an example to illustrate that the name is ZSpace, because a Web project to illustrate more representative.

Select "Run/debug Configuration", add a "Django server", and then configure it to write like this

Please pay attention to the number of points in the figure, the specific meaning will not have to explain it, ^_^

Then you can break the point and debug as if you were debugging locally. This step is too simple, remember to modify the source code after synchronization to the server to continue the next debugging.

Python Remote Debugging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.