If you’re using Ubuntu on Raspberry Pi, you first need to set up an openssh server to use Visual Studio Code’s remote access tooling. That’s easy enough: just use the built-in package management tools to install the appropriate packages, and then use the Windows command line to ssh to your Pi to set up the appropriate keys.
- I want to run Visual Studio Code Remote Development using SSH to my Raspberry Pi 3 Model B+ running Raspbian GNU/Linux 9 (stretch). I have tried to follow the 'Getting started' instructions.I run the command Remote-SSH: Connect to Host., but I get the message Can't connect to admin@pihole.local: unreachable or not Linux x8664 (Linux armv7l ). As far as I know, Raspbian is 32 bit.
- Visual Studio Code supports macOS, Linux, and Windows - so you can hit the ground running, no matter the platform. Edit, build, and debug with ease. At its heart, Visual Studio Code features a lightning fast source code editor, perfect for day-to-day use.
Like a lot of people out there, I like to tinker with the Raspberry Pi. Until now, I used it mailny as a small linux host to run services, as a media server, as a NextCloud server, … You know, the usual suspects. But lately, I started to play with electronics. I bought a breadboard and a discovery pack to get going. Obviously, that means coding tiny programs in C or Python. Python was my choice.
I always install my RPi's headless. I don't need the overhead of a graphical interface and feel at home in a shell. Installing VSCode is going to be difficult. Right! More on that later. My editor of choice is Vim. I'm far from being a guru at it, but I get things done pretty easily for my needs. A few years ago, I had used vundle and a long list of plugins painstakingly configured and customised to make Vim a real power house. That took time, research, trial and errors, … I wasn't ready to invest the time for that, I wanted to start playing with little circuits.
So naked Vim it is. One script later and missing auto completion, I decided to look for a better solution: SpaceVim. That's even better than my long gone power house Vim setup. I very quickly found how to configure it as a Python IDE. I was relieved, this was working pretty nice. A bit sluggish, but usable.
Then a colleague sent me a link to Remote Development: a VSCode extension pack that looked interesting. He thought the remote-container extension would get my blood flowing. Rightly so. But the remote-ssh extension triggered my interest out of immediate necessity. I have no use for the 3rd extension for WSL (the Windows Subsystem for Linux). I don't use WSL, I work on a Mac. But I am sure Windows users will love it. I did not install the pack, but remote-ssh and remote-container are now part of my favorite extensions.
Visual Studio Code Ssh Raspberry Pi Connection Refused
I suggest to get VSCode Insiders as the extensions are still in preview as of this writing.
I installed the remote-ssh extension and my ssh config server names showed up in the VSCode connection menu. I just needed to pick and chose. Here is a sample of my ssh config file.
If you need more details, it's all very well explained here.
The connection gets established. On the remote host, you'll find the .vscode-server-insiders folder in your home directory on the remote host as expected.
VSCode shows no extensions on the remote host. The extensions window is now split to show local and remote extensions. I can just browse locally installed extensions and with the click of the mouse, they are installed on the remote host. Very nice.
Time to test it. I'll create a python virtual environment, select the python interpreter, open a python file, …, yes, install pylint for me please, then I install RPi.GPIO,…, we should be good to go.
And I get this: 'Operating system does not meet the minimum requirements of the language server. Reverting to alternative, Jedi'. Hummm!
And I see a problem in the VSCode Problems tab. The linter does not recognize the imported lib and all GPIO methods are shown as not existing.
Auto completion works perfectly though.
I decided to disable Jedi and so far so good. I do not know if I just get a speed penalty for using the Microsoft Python Analysis Engine. But if I do, it ok. It's a Raspberry Pi, I'm gonna be fine.
Install Visual Studio Code Raspberry Pi
FWIW, I tested another Python project on a Centos 7 virtual machine and it worked without any issues. So, fingers crossed this is just a speed thing.
Added bonus, when remote connected to a host, the VSCode shell is not the local shell any more, it is, as expected the remote shell. So you get to use all the powerful features of the editor and you can use the embedded shell for all your cli needs.
The remote-ssh extension is great and can be useful in many ways:
- For people that don't know how to use Vim or Emacs
- If you want to have different setups for different tasks on different remote hosts
- If you are tired of using SCP to move files back and forth
- ...
So, sure, it is super convenient, but what is the deal with the Raspberry Pi? Is it just to bait you because the Pi has that cool/fun factor?
No! Try to install the RPi.GPIO module on your Mac, or Windows host. It fails! Google around and you'll see a few people wanted to code from the comfort of their main machine. Well, in this particular case, you can't. You need to develop on the Pi itself. There is even a fake-rpi library (that I have not tested) to avoid having to develop on the Pi. I can use the real deal from the comfort of my Mac and VSCode, having all my customisations, drop down to the shell if needed, execute my program and test the results on my breadboard. Priceless!
Try it out!