Use Pycharm to debug remote code

background

The working machine is a Windows computer, and many times I need to code on the Mac computer and cooperate with the iPhone simulator, so I used to use VNC or Sunflower to remotely program the Mac, which is actually acceptable, but the most uncomfortable thing for me is Use of shortcut keys. As we all know, the shortcut keys of Windows need to be switched for the Mac, and many shortcut keys on the Mac do not know what they are, and the remote will also be affected by network fluctuations, sometimes the mouse does not move, and the keyboard typing response is not smooth , I won’t mention other uncomfortable points.

Synchronize remote code

Using the Deployment function that comes with pycharm, direct remote coding can be realized.

First configure SSH Configuration, fill in the IP and user name and password of the Mac machine I want to remote, and then Test Connection, you can give this configuration a name, such as iOSmachine.
Please add a picture description

Deployment Tools - Deployment - Configuration

Please add a picture description

About Connection

/Users/<username>You don’t need to configure it yourself, click Autodetect to automatically generate a path on my Mac computer

Please add a picture description

About Mapping

This is the key. The local path is configured as the project path of my local code, and the deployment path is configured as a path on the Mac machine. In the future, the files in these two paths can be synchronized with each other.

Please add a picture description

For convenience, both sides go to the same directory name mobile_develop, and then clone the same project code to the two machines.

Why do you want to do this, because I found that if you just clone the git project code on one side and synchronize the path to another machine, open it with pycharm, you can’t use the git blame function, and you can submit the code on both sides wait.

Of course, Deployment is not what I use in many cases. For example, if you need to debug the code on a server machine without a graphical interface, then you can connect remotely with ssh, synchronize the code to the local, execute the debugging locally, and after the code is modified, synchronize back to server.

After modifying the code locally, how to synchronize to the remote machine, and how to keep some files and only synchronize files in a certain directory can be explored and used in the Deployment menu.

Please add a picture description

Please add a picture description

A commonly used function, ignore some unimportant files, configure in Deployment - Options

Please add a picture description

Interpreter

After synchronizing the code, you need to debug. If you have the same environment locally as the remote, then it will be easy. Instead of using the remote python, you can directly use the local Python version to debug.

But usually the remote environment is different from the local one, so when I debug this project, I need to use the remote environment, such as using the Python version on the Mac machine, and configure the Python Interpreter at this time

choose first On SSH,

Please add a picture description

Fill in the host and username of my remote Mac machine, and operate a few steps, as shown below

Please add a picture description

After configuration, you need to wait for loading.

Finally, you can code, debug, and run on pycharm on Windows, and the environment is essentially the Mac environment.

For example, if I execute the app code to start the emulator on Windows, the app on the Mac computer can run. From then on, I don't need to open the remote software window to code, which is comfortable.

important point

Some codes use the operations in the Mac environment variables. When operating under this function, errors may occur. For example, if the jfrog environment variable is configured in the Mac environment, if the remote code is executed locally through ssh on win, the os.popen('jfrog xxx xxx')expected result cannot be obtained, but it should be used os.popen('/usr/local/bin/jfrog xxx xxx'). The problem of the environment variable needs to be paid attention to.

Guess you like

Origin blog.csdn.net/qq_31362767/article/details/131145922