Abbreviation for "Visual Studio Code", a source code editor developed by Microsoft. It is said that it is rapidly gaining popularity as a free, lightweight, and multifunctional editor.
Since the 2019/10 version, the SSH connection function to RaspberryPi (ARM v8) is officially supported, so I wrote an article about the result of trying Python code remote editing in Raspberry Pi.
** In conclusion, we were able to realize a comfortable remote development environment, such as debugging with breakpoints! ** **
・ RaspberryPi (RaspberryPi3 Model B in this example) -PC connected to the same network as above (Windows 10 in this example) -Visual Studio Code 1.39.2 or later (installed on the above PC, 1.44.2 is used in this example)
I referred to the following article https://qiita.com/hukatama024e/items/9f96730381f0a34c6da6
[This article "For Public Key Authentication"](https://qiita.com/c60evaporator/items/2384416f1122ae124f50#%E5%85%AC%E9%96%8B%E9%8D%B5%E8%AA%8D % E8% A8% BC% E3% 81% AE% E5% A0% B4% E5% 90% 88% E6% 89% 8B% E9% A0% 86) to establish SSH public key authentication and config file Please save.
In addition, please save the config file in the following folder in the PC C: \ Users \ [username] \ .ssh
Please install VS Code on ** PC side **
Reference article https://qiita.com/psychoroid/items/7d85ae6bade4a67aedb1
Start VSCode and follow the steps below to install Remote Development
Follow the steps below to select the SSH server to connect to = RaspberryPi ("raspi" in the figure below)
A new window will open and you will be asked to select a platform, so choose Linux
You will be asked for a password for public key authentication, enter it and press Enter
The first connection takes time, so wait for a while. If successful, you can access the files in the Raspberry Pi by clicking the red frame in the figure below.
From here onward, you can use the console, but we will proceed with the description on the assumption that you will operate with the GUI.
**-Create an empty file ** Create an empty file by selecting "File"-> "New File"
** ・ Description of code contents ** For example, write the following Python code (calculate and display the standard deviation with numpy)
**-Save code ** "File"-> "Save As"-> specify save path-> "OK"
**-Try running from the console ** Open the console by selecting "Terminal" → "New Terminal" Go to the folder with the code and
python3 test.py
Run python code in You can see that the result is output to the console normally.
With VS Code GUI, you can even debug the code. You can also stop at a breakpoint, so there is no doubt that development efficiency will increase!
**-Install Python linter ** If you have already installed it locally on your PC, click "install in SSH: [hostname]" to install the Python linter on your Raspberry Pi as well.
When the installation is complete, "Reload Required" will appear, so click it to restart.
**-Open a working folder (usually the folder with the code) **
**-Debugging ** After opening the code you want to debug, execute the following operation
The console will open and debug will be performed
** ・ Breakpoint operation check ** As shown in the figure below, you can stop processing at a breakpoint and check the variable contents.
Now you can remotely debug the code in your Raspberry Pi with VS Code. ** The environment for quick development with GUI is ready, and I am personally satisfied with the result! ** **
When building an environment with pyenv on the Raspberry Pi side, I get the following error when importing a library installed with pip.
Error details: Unable to import'bluepy' pylint (import-error)
As described in here, It seems that the cause is that the location of Python referenced when debugging with VS Code and Python of pyenv are different.
/home/[username]/.vscode-server/extensions/ms-python.python-‥/pythonFiles/.vscode It is in settings.json Open and add the last line below
settings.json
{
//
//Original description
//
"python.pythonPath": "[Python location for pyenv]"
}
Create a ".vscode" folder in the work folder opened in ⑥, Create the following settings.json file in the folder
settings.json
{
"python.pythonPath": "[Python location for pyenv]"
}
This should force pyenv's Python to run
Recommended Posts